我有以下查询:
List<Models.PricingFormula> formulasInCat = new List<Models.PricingFormula>();
productsInCat = (from x in Model.PPPVMs
where x.CategoryId == category.ProductCategoryId select x).ToList();
查询没有返回任何记录,我得到的错误是:
Value cannot be null.
处理这个问题的正确方法是什么?
最佳答案
您可以在调用 ToList()
方法之前使用 DefaultIfEmpty()
。
关于c# - 当查询没有返回记录时,会抛出 Linq Cannot be Null 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16869473/