【发布时间】:2019-02-22 12:09:49
【问题描述】:
我正在尝试在 LINQ 中为两个 vars 执行左外连接,但在选择所需的列时,我在想要 Nullable decimal 的地方收到 Object reference not set to an instance of an object 错误。
var FLS = (from ee in SumTillFYEnd
join es in SumTillFYStart on ee.Account equals es.Account into temp
from t in temp.DefaultIfEmpty()
select new
{
Account = ee.Account, // As of here it works
BeginDr = (t.DrStartCF == 0) ? (decimal?) null : t.DrStartCF // Here I get error Object reference not set to an instance of an object.
});
有时 SumTillFYEnd 有时 SumTillFYStart 变为空。我想加入应该使用默认值,以防任何一个或两个都为空。
【问题讨论】:
-
用
t == null替换t.DrStartCF == 0 -
LINQ 总是显示为空
-
你不能以
IQueryable的形式运行LINQ 查询,作为一个整体,它会被翻译成SQL 吗? -
在我的情况下不,我正在将一个长 sql 存储过程重写到 LINQ。
标签: linq asp.net-core-2.1 ef-core-2.1