0

I am struggling with the following. Can anyone help how to do this?

How to write nhibernate query to the following

select * from tableA where description like (*Any of the items from a lst*)

List<string> lst = new List<string>
{
     "AAA","BBB","CCC","DDD"
}

At the moment i am selecting all the records and applying this filtering on the in memory collection.

The actual code:

    private List<string> lst = new List<string>{
        "AMV",
        "BMVi",
        "CMV",
        "DTL"
    }
    public virtual IEnumerable<Asset> ReplayAssets(DateTime updatedDateTimeFrom, DateTime updatedDateTimeTo)
    {
        Asset assetAlias = null;
        var query = Session.QueryOver(() => assetAlias);

        //Here i need to add something like
        query.where(()=>assetAlias.title.like(*any item in the above list lst* )

        query.Where(() => assetAlias.LastUpdatedDate.IsBetween(updatedDateTimeFrom).And(updatedDateTimeTo));

        return query.Future<Asset>();
    }

Thanks

Mukil Deepthi
  • 6,072
  • 13
  • 71
  • 156

1 Answers1

0

It's quite simple.

var lst = new List<string>
{
  "AAA", "BBB", "CCC", "DDD"
};

var items = Session.Query<TableA>
  .Where(x => lst.Contains(x.Description))
  .ToList();
gnllucena
  • 804
  • 7
  • 6