![](/img/trans.png)
[英]How can I implement String.Concat(object, object) to L2E framework?
[英]How can I perform this query using L2E?
我有2張桌子:
Activities ActivityKeywords
********** ****************
ID --> ActivityID
Name Keyword
我需要返回與特定關鍵字匹配的所有活動。
var q = from a in Context.Activities
where a.Keywords.Any(k => k.Keyword == someKeyword)
select a;
正如我在評論中所說,在LINQ to Entities中使用join幾乎總是錯誤的。 應該使用關系屬性代替。
如果定義了關系,請查看Craig Stuntz的答案以更簡潔的方式
我之前的回答是錯誤的,但這對我有用。
var activities = from a in db.Activities
join ak in db.ActivityKeywords on a.ID equals ak.ActivityID
where ak.Keyword == "yourkeyword"
select a;
我想你需要像
Give me all Activities which ID are in a list of ActivitiyKeywords.ID's
如果這是您的問題,則可以嘗試以下操作:
var ids = from k in db.ActivityKeywords select k.ActivityID;
var result = from a in db.Activities where ids.Contains(a.ID) select a;
更多信息在這里 。
var results = (from a in Activities
from k in ActivityKeywords
where k.Keyword == "keyword" && k.ActivityID == a.ID
select a).Distinct();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.