Batch Update in NHibernate

前端 未结 6 1143
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 09:04

Does batch update command exist in NHibernate? As far as I am aware it doesn\'t. So what\'s the best way to handle this situation? I would like to do the following:

6条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 09:22

    Starting NHibernate 3.2 batch jobs have improvements which minimizes database roundtrips. More information can be found on HunabKu blog. Here is example from it - these batch updates do only 6 roundtrips:

    using (ISession s = OpenSession())
    using (s.BeginTransaction())
    {
        for (int i = 0; i < 12; i++)
        {
            var user = new User {UserName = "user-" + i};
            var group = new Group {Name = "group-" + i};
            s.Save(user);
            s.Save(group);
            user.AddMembership(group);
        }
        s.Transaction.Commit();
    }
    

提交回复
热议问题