NHibernate using QueryOver with WHERE IN

前端 未结 3 1286
孤城傲影
孤城傲影 2020-12-24 05:07

I would create a QueryOver like this

SELECT *
FROM Table
WHERE Field IN (1,2,3,4,5)

I\'ve tried with Contains method but I\'ve

3条回答
  •  孤城傲影
    2020-12-24 05:33

    This works and is more elegant

    var Strings = new List { "string1", "string2" };
    
    var value = _currentSession
    .QueryOver()
    .Where(x => x.TProperty == value)
    .And(Restrictions.On(y=>y.TProperty).IsIn(Strings))
    .OrderBy(x => x.TProperty).Desc.SingleOrDefault();
    
    where T is a Class and TProperty is a property of T
    

提交回复
热议问题