問題:下面的代碼行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