[英]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.