Fluent NHibernate does not create IN part of WHERE clause

后端 未结 3 418
借酒劲吻你
借酒劲吻你 2021-01-12 23:20

I have Fluent NHibernate Linq queries where I check values based on run time arrays. A basic example would be something like:

var array = [1,2,3,4,5,6];
usin         


        
3条回答
  •  离开以前
    2021-01-12 23:43

    Use Any:

     return session.Query().Where(x => array.Any(y => y == x.CompareVal)).ToList();
    

    Your repository pattern (using plain Func) automatically materializes your query to list, if you want something to be deferredly executed, use IQueryable, don't use Func only

    Something to note - I have a Generic Repository class that all of these calls are funneled through. The Query method is as follows:

    public IList Query(Func criteria)
    {
      using (var session = SessionProvider.SessionFactory.OpenSession())
      {
        return session.Query().Where(criteria).ToList();
      }
    }
    

    Your repository just mimic what is already provided out of the box by NHibernate

提交回复
热议问题