I have the following model.
Subscription Packages PackageWidgets Widgets
------------ -------- -------------- -------
ID ID < PackageID ID
PackageID > WidgetID >
我正在使用实体框架4和<代码>Subscription与Package
的关系。 <代码>Package与<代码>Widgets清单的关系。
我在使用Linq时试图获得一份allWidgets
清单,如果将其列入目前的订阅。 也许,这要归功于我的卡片背景,即我看不到林克的问候。 结构将包括一个来自温得植被的SlectT,一个LEFT JOIN,通过一个基于在子保单中通过的内容的子描述、包裹和包装产品。
The output I would expect would be something like WidgetID,IsIncluded
such that I would have all Widget IDs and a boolean indicating the inclusion status.
我甚至似乎甚至无法稍微接近工作,以显示我迄今所做的工作。
没有人能够就如何完成我的询问给我一些见解?
Update: Here is what I ve come close with, but it still doesn t work. Maybe it will help illustrate what I am trying to accomplish though:
from subscription in Subscriptions
where subscription.ID == 3
let subWidgets = subscription.Package.Widgets
from widget in Widgets
join subWidget in subWidgets on widget.ID equals subWidget.ID into joined
from list in joined.DefaultIfEmpty()
select new {
ID = widget.ID
,Selected = subWidget.ID != null
}
Update #2 Thanks to the accepted answer, this is what I ended up going with - which does what I need:
from widget in Widgets
from subWidgets in
from subscription in Subscriptions
where subscription.ID == 3
select subscription.Package.Widgets
orderby widget.ID
select new {
Name = widget.WidgetName,
Available = subWidgets.Contains(widget)
}
Thanks for the assist!