0

I'm using Fluent NHibernate and try to do many updates. First came in mind is code like this:

  using (ISession s = OpenSession())
  using (s.BeginTransaction())
  {
      IList<SomeType> items s.QueryOver<SomeType>()
          .Where(someCondition)
          .List();
      items.ForEach(i => {
          i.Foo = "bar";
          s.Update(i);
      });  
      s.Transaction.Commit();
  }

But problem is in that every updating item must be loaded before do update. So database queried twice. In SQL it can be done with one query and i believe exist some way to do this with one query in NHibernate. And found doc for Load method that not actually load item from db and only work with some proxy instead and hit database only when i do update/delete.

Exist some method in NHibernate that load not items itself but proxy like Load?

Daniil
  • 96
  • 8
  • Sorry to be obtuse, but NH is really the wrong tool for this kind of set-based operation. The most efficient way of doing this would be to use HQL or raw SQL. Saying that, have you investigated the use of a 'stateless session'? It might be an effective compromise. – David Osborne Aug 07 '17 at 12:47
  • In company where i write this code we don't use queries in text form. Performance in this case not so bad for write sql or HQL. IStatelessSession have similar to ISession interface so will not help with that. – Daniil Aug 07 '17 at 13:01
  • @DavidOsborne Thank you for answer anyway. – Daniil Aug 07 '17 at 13:34
  • No problem. Some other ideas here: https://stackoverflow.com/q/780940/1162077 – David Osborne Aug 07 '17 at 13:44

1 Answers1

0

For now for update large data best way is use HQL or raw SQL how mentioned @DavidOsborne.

I unfortunately not found any other methods that works lazy as Load method.

Daniil
  • 96
  • 8