How to delete multiple db entities with Nhibernate?

前端 未结 3 1249
情书的邮戳
情书的邮戳 2021-02-05 13:47

What is the best practice for this problem? Is there any batching features built-in?

Sample code:

using (ITransaction transaction = _session.BeginTransa         


        
3条回答
  •  误落风尘
    2021-02-05 14:25

    you can Use HQL to delete multiple objects

    Look for delete here - for session.delete example

    HQL DELETE example (you can use IN with HQL):

    ISession session = sessionFactory.OpenSession();
    ITransaction tx = session.BeginTransaction();
    
    String hqlDelete = "delete Customer c where c.name = :oldName";
    // or String hqlDelete = "delete Customer where name = :oldName";
    int deletedEntities = session.CreateQuery( hqlDelete )
            .SetString( "oldName", oldName )
            .ExecuteUpdate();
    tx.Commit();
    session.Close();
    

提交回复
热议问题