我想檢查下面的代碼,如果沒有找到匹配,它不應該拋出對象引用null錯誤。有沒有辦法可以檢查AddRange()方法linq語句中的空對象?
itm.lstCustomziation.AddRange(
(from xx in db.vw_DressingCustomization
where xx.CatID == itm.HeaderName.Value && xx.ProductID == itm.ProductID
select new itmCustomization()
{
catId = (int)xx.CatID,
custType = customizationType.Dressing,
isCustomziationDisplay = xx.IsDefaultDisplay,
isFixLimit = (bool)xx.isDefaultLimit,
maxLimit = (short)xx.DefaultFreeCount,
itmName = xx.Description,
isItemDefault = xx.IsDefaultDisplay,
price = (double)xx.MainPrice,
proId = (int)xx.ProductID
}).ToList<itmCustomization>());
其實'ToList()'不應該返回null。如果序列爲空,則返回空列表。 –
from xx in db.vw_DressingCustomization where xx.CatID == itm.HeaderName.Value && xx.ProductID == itm.ProductID here it failure .. – NoviceToDotNet
Linq是SQL還是Entity Framework? –