当list具有空值时,Linq返回NullReferenceException

时间:2017-03-29 09:02:40

标签: c# linq

我想获得一份客户详细信息列表,而某些客户的Mobile_No为空,当我运行下面的代码时,由于空值而抛出NullReferenceException,我是否可以使用空值获取此列表? / p>

    public IList<CustomerMdl> AddSupplier_gridCustomer()
    {
     var ShopModel = icustomerrepository.GetList(x => x.Customer_Id != 0)
            .Select(y => new CustomerMdl
            {
                Customer_Id = y.Customer_Id,
                Customer_Name = y.Customer_Name,
                RouteName = y.Route.RouteName,
                Customer_TypeName = y.Customer_Types.Customer_Type_Name,
                Customer_GradeName = y.Customer_Grades.Customer_Grade_Description,
                Land_No=y.Land_No,
                Mobile_No=y.Mobile_No,
                VAT = true,
                NBT = true,      
                Active=y.Active,
            }).OrderBy(x => x.Customer_Name).ToList();
        return ShopModel;
    }

0 个答案:

没有答案