问题:下面的代码行price = co?.price ?? 0,
给我上面的错误。但如果我从co.?
删除?
它工作正常。我试图按照this MSDN example他们在哪里使用?
在线select new { person.FirstName, PetName = subpet?.Name ?? String.Empty };
所以,我似乎需要了解何时使用?
与??
和什么时候不使用。表达式树lambda可能不包含空传播运算符
错误:
表达式树lambda不能包含空传播算子
public class CustomerOrdersModelView
{
public string CustomerID { get; set; }
public int FY { get; set; }
public float? price { get; set; }
....
....
}
public async Task<IActionResult> ProductAnnualReport(string rpt)
{
var qry = from c in _context.Customers
join ord in _context.Orders
on c.CustomerID equals ord.CustomerID into co
from m in co.DefaultIfEmpty()
select new CustomerOrdersModelView
{
CustomerID = c.CustomerID,
FY = c.FY,
price = co?.price ?? 0,
....
....
};
....
....
}
请发布错误... –
我希望C#支持这个人! – nawfal