nhibernate / nhibernate-core

NHibernate Object Relational Mapper
https://nhibernate.info
GNU Lesser General Public License v2.1
2.13k stars 929 forks source link

Bulk updating with Query Update does not have implementation for IsIn operator #2333

Closed pastaav closed 4 years ago

pastaav commented 4 years ago

I am trying to use the new bulk updating feature of NHiberate 5 but runs inte an problem with the visitor that handle IsIn operation. We are using the IsIn operation for the same domainobject in other parts of the application with QuerOver so I am reasonably confident the mapping is right but when trying to apply the same pattern for Query it does not work.

Case that works session.QueryOver<MyObject>().Where(x => x.Id.IsIn(chunkOfIds)).List<T>().ToList()

Case that does not work session.Query<MyObject>().Where(f => f.Id.IsIn(chunkOfIds)) .Update(x => new MyObject{ SomeValue = 0});

2020-03-19 12:05:15,098 ERROR Update: Method error: Boolean IsIn(System.Object, System.Collections.ICollection), Type: NotSupportedException, at NHibernate.Linq.Visitors.HqlGeneratorExpressionVisitor.VisitMethodCallExpression(MethodCallExpression expression) at NHibernate.Linq.Visitors.HqlGeneratorExpressionVisitor.VisitExpression(Expression expression) at NHibernate.Linq.Visitors.QueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index)

bahusoid commented 4 years ago

IsIn works only with QueryOver. Don't expect that something that works in QueryOver will work with Query - it's completely different API.

In Query (LINQ) you need to use Contains: .Where(f => chunkOfIds.Contains(f.Id))