【发布时间】:2011-05-05 23:06:51
【问题描述】:
我似乎无法弄清楚如何正确编写此查询。我尝试了各种组合,但没有任何效果。
以下是我的数据库模型的相关部分:
我需要选择与给定类别和组匹配的产品,以及与给定年份、品牌、型号、子型号匹配的产品。这是我在下面完成的:
ItemList = From P In gDataContext.Products.Include("Groups").Include("Groups.Category1").Include("LookupYearMakeModels") From G In P.Groups Where G.Category = Cat And G.Grp = Group From Y In P.LookupYearMakeModels Where Y.Year = YMM.Year And Y.Make = YMM.Make And Y.Model = YMM.Model And Y.Submodel = YMM.Submodel Select P
我现在还必须选择与类别和组匹配但通用的产品(Product.Univeral = True)。
我目前正在编写两个查询,一个在上面,一个在下面。我通过简单地使用 ItemList.AddRange(ItemList2)
来合并两者的结果ItemList2 = From P In gDataContext.Products.Include("Groups").Include("Groups.Category1") where P.Universal From G In P.Groups Where G.Category = Cat And G.Grp = Group Select P
但我想将两个查询合并为一个,避免合并结果。我该怎么做?
感谢您的帮助!
【问题讨论】:
-
我不会使用像 Group 这样的保留词作为我的一个对象的名称。
标签: asp.net vb.net entity-framework linq-to-entities entity-framework-4