Update Top n using NHibernate

后端 未结 1 427
日久生厌
日久生厌 2021-01-25 04:55

How can I make NHibernate produce this t-sql request ?

Update top (n) Tasks set MODIFICATIONS where CONDITION

I don\'t want to do a Transaction + batch update.<

相关标签:
1条回答
  • 2021-01-25 05:17

    Please, check this:

    • 13.3. DML-style operations

    a cited code snippet:

    ISession session = sessionFactory.OpenSession();
    ITransaction tx = session.BeginTransaction();
    string hqlVersionedUpdate = "update versioned Customer set name = :newName where name = :oldName";
    int updatedEntities = s.CreateQuery( hqlUpdate )
            .SetString( "newName", newName )
            .SetString( "oldName", oldName )
            .ExecuteUpdate();
    tx.Commit();
    session.Close();
    

    So, this way, we can defin UPDATE with HQL (using our domain model) and executing the udpate directly at once on DB side

    NOTE: for more details also check this blog post: NHibernate – Executable DML by Ayende

    0 讨论(0)
提交回复
热议问题