[英]linq to entities where condition issue
我试图列出满足条件#1或#2的所有行,并返回#1和#2的两行。 但问题是仅返回满足一个条件(#1或#2)的行。
var query = (from c in context.Tasks where
&& ((c.FK_PrivacyID == 1 && c.Fk_TaskFollowerTypeID == 1)
|| (c.TaskFollower == FK_userID && c.Fk_TaskFollowerTypeID == 2))
orderby c.CreatedDate descending
orderby c.LastModificationDate descending
select c)).ToList();
感谢任何帮助。
您需要条件1而不是条件2->(condition1)&&!(condition2)
var query = (from c in context.Tasks where
((c.FK_PrivacyID == 1 && c.Fk_TaskFollowerTypeID == 1)
&& !(c.TaskFollower == FK_userID && c.Fk_TaskFollowerTypeID == 2))
orderby c.CreatedDate descending
orderby c.LastModificationDate descending
select c).ToList();
尝试在where子句和不必要的括号后加上第一个“ &&”
var query = (from c in context.Tasks where
(c.FK_PrivacyID == 1 && c.Fk_TaskFollowerTypeID == 1)
|| (c.TaskFollower == FK_userID && c.Fk_TaskFollowerTypeID == 2)
orderby c.CreatedDate descending
orderby c.LastModificationDate descending
select c)).ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.