Search code examples
c#nhibernatewhere-clausequeryover

Using QueryOver how do I write a Where statement against an "is in"


When using QueryOver, I normally write a Where clause where the field exactly matches a value:

var subset = _session.QueryOver<ProviderOrganisation>()
.Where(x => x.Type == "Hospital")
.List<ProviderOrganisation>();

But now I want to match the field against a list of values, so in SQL something like a "Where x is in ():"

var subset = _session.QueryOver<ProviderOrganisation>()
.Where(x => x.Code is In (ListOfSubsetCodes))
.List<ProviderOrganisation>();

How do I do that please?

Thanks


Solution

  • You can use contains to do a in:

    .Where(x => ListOfSubsetCodes.Contains (x.Code))