您可以在实体框架中为实体添加“或”条件吗?例如:
属性 1 == (1 或 2 或 3)
输入“1 || 2 || 3”或“1,2,3”或“1 or 2 or 3”的值时收到的消息返回此消息:
condition is not compatible with the type of the member
您可以在实体框架中为实体添加“或”条件吗?例如:
属性 1 == (1 或 2 或 3)
输入“1 || 2 || 3”或“1,2,3”或“1 or 2 or 3”的值时收到的消息返回此消息:
condition is not compatible with the type of the member
你需要做:
var results = entityCollection.Where(entity => entity.Property1 == 1 || entity.Property1 == 2 || entity.Property1 == 3);
您还应该查看谓词构建器: http ://www.albahari.com/nutshell/predicatebuilder.aspx
它有点高级,但如果你必须动态链接条件,那是你最好的选择。
foreach (string keyword in keywords)
{
string temp = keyword;
predicate = predicate.Or (p => p.Description.Contains (temp));
}
没试过这个,但你可以尝试使用contains
. 不确定性能,但代码更小:
int[] vals = new int[] { 1, 2, 3, 4 };
var results = entityCollection.Where(entity => vals.Contains(entity.Property1));