LINQ左联接错误
|
我已经在LINQ中编写了以下查询以执行左联接,但其抛出错误:
var qry = from c in dc.category_feature_Name_trans_SelectAll_Active()
join p in dc.product_category_feature_trans_SelectAll()
on c.cft_id equals p.cft_id into cp
from p in cp.DefaultIfEmpty()
select new
{
c.cft_id,
c.feature_id,
c.feature_name,
p.product_id ,
p.value
};
错误:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 57: on c.cft_id equals p.cft_id into cp
Line 58: from p in cp.DefaultIfEmpty()
error Line 59: select new
Line 60: {
Line 61: c.cft_id,
请帮我。
没有找到相关结果
已邀请:
4 个回复
土投
将返回一个具有单个null值的序列。 这意味着您必须考虑以下事实:
可以为null。现在,您还没有真正说出在这种情况下要发生的事情。您可能想要这样的东西:
...或者您可能需要一些其他处理。我们不知道
或
的类型,这没有帮助。 (例如,如果
是值类型,则您需要对上述代码进行更多处理。)
哭木算
可以是
。您需要考虑到这一点。 这是应该工作的查询,尽管我不确定
是哪种值。如果value是引用类型,则查询将起作用。如果值是值类型,则使用类似于“ 9”的类型转换。
森含械
眠缝