Fluent NHibernate does not create IN part of WHERE clause

后端 未结 3 424
借酒劲吻你
借酒劲吻你 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:36

    Does it make a difference if you change your Query method to the following ?

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

    This is how I usually proceed with a generic Query :

        public List GetEntitiesLinq(Expression,IQueryable>> myFunc)
        {
            var t = (myFunc.Compile())(_session.Query()) ;
            return t.ToList();
        }
    

    Then how I would use it in your case :

    var myObjList = myQueryManager.GetEntitiesLinq(x=>x.Where(myObj => array.Contains(myObj.CompareVal)));
    

    Hope this will help

提交回复
热议问题