NHibernate using QueryOver with WHERE IN

Faber picture Faber · Mar 23, 2011 · Viewed 49.8k times · Source

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 encountered the Exception

"System.Exception: Unrecognised method call: System.String:Boolean Contains(System.String)"

Here my code

var qOver = _HibSession.QueryOver<MyModel>(() => baseModel)                                                                
  .JoinAlias(() => baseModel.Submodels, () => subModels)
  .Where(() => subModels.ID.Contains(IDsSubModels))
  .List<MyModel>();

Answer

Faber picture Faber · Mar 24, 2011

I've found the solution!! :-)

var qOver = _HibSession.QueryOver<MyModel>(() => baseModel)
    .JoinAlias(() => baseModel.Submodels, () => subModels)
    .WhereRestrictionOn(() => subModels.ID).IsIn(IDsSubModels)
    .List<MyModel>();