How do you do a SQL style 'IN' statement in LINQ to Entities (Entity Framework) if Contains isn't supported?

后端 未结 4 1813
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-13 16:57

I\'m using LINQ to Entities (not LINQ to SQL) and I\'m having trouble creating an \'IN\' style query. Here is my query at the moment:

var items = db.InventoryIt         


        
4条回答
  •  余生分开走
    2021-02-13 17:43

    My workaround is to convert the entities result to a List and after that apply the Contains().

    Example:

    var items = db.InventoryItem
                    .Include("Kind")
                    .Include("PropertyValues")
                    .Include("PropertyValues.KindProperty")
                    .ToList()
                    .Where(itm => valueIds.Contains(itm.ID));
    

提交回复
热议问题