我有以下表LINQ请求多到许多
Users
- ID
- FirstName
- LastName
MultiplyItems
- ItemID
- Title
UserMultiplyItems
- UserID
- ItemID
我有一个可变
List<int> delegateList = {1, 3, 5};
其中1,3,5是的ItemID
我想选择所有用户,其中至少有一个ItemID链接可选用户。 我尝试以下操作:
var result = from i in _dbContext.Users
where
((delegateList == null) || i.MultiplyItems.Any(p=> delegateList.Any(a => a == p.ItemID)))
select new UserModel()
{
....
};
但它不起作用。错误:
Cannot compare elements of type 'System.Collections.Generic.List`1'. Only primitive types, enumeration types and entity types are supported.
如何正确地做到这一点? 感谢
谢谢,但是如何检查delegateList = null(然后忽略此部分)? –
结构如果不起作用... –