繁体   English   中英

Linq to SQL尝试使用DefaultIfEmpty()左联接导致查询运算符'DefaultIfEmpty'使用不支持的重载。 错误

[英]Linq to SQL attempting left join with DefaultIfEmpty() causing Unsupported overload used for query operator 'DefaultIfEmpty'. error

这是我第一次尝试通过linq进行左联接,我查看了堆栈溢出和Google,但我尝试过的所有方法均无效(很可能是由于我自己缺乏理解)。 我正在尝试执行以下查询:

IQueryable<MyType> pQ = (from prd in dc.ProductDatas 
join cc in dc.CategoryProducts.DefaultIfEmpty(defaultCP) 
on prd.ProductID equals cc.ProductID 
where cc.CatID == CatID
orderby cc.OrdWithinInCategory 
select prd);

我将defaultCP定义为:

CategoryProduct defaultCP = new CategoryProduct {ID = 1,CatID = CatID, OrdWithinInCategory = 999};

我收到以下错误:

用于查询运算符“ DefaultIfEmpty”的不支持的重载。

说明:执行当前Web请求期间发生未处理的异常。 请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。

异常详细信息:System.NotSupportedException:用于查询运算符'DefaultIfEmpty'的不支持的重载。

我的代码中有明显的错误吗?还是需要完全尝试另一种方法。 任何帮助,不胜感激。

使用AsEnumerable()。

CategoryProduct defaultCP = new CategoryProduct {ID = 1,CatID = CatID, OrdWithinInCategory = 999};

IQueryable<MyType> pQ = (from prd in dc.ProductDatas 
                        join cc in dc.CategoryProducts.DefaultIfEmpty(defaultCP) 
                           on prd.ProductID equals cc.ProductID 
                        where cc.CatID == CatID
                        orderby cc.OrdWithinInCategory 
                        select prd)
               .AsEnumerable()
               .DefaultIfEmpty(defaultCP).First();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM