.ToList()抛出“对象引用未设置为对象实例”的异常。

时间:2014-01-13 08:22:10

标签: sql asp.net-mvc linq

private void BindDataGridDetails(string p)
{
    var allClients = new List<DataLayer.Client>();

    if (string.IsNullOrWhiteSpace(p))
    {
        allClients = entities.Clients.ToList();
    }
    else
    {
        allClients = entities.Clients.Where(m =>m.CompanyName.Contains(p)||m.ContactPersonName.Contains(p)).ToList();
    }

    allClients = entities.Clients.ToList();

    var finalClientList = allClients.Select(v => new
    {
        v.UserId,
        v.MobileNumber,
        v.Designation,
        v.CompanyName,
        v.ContactPersonName,
        EmailAddress = v.User.EmailAddress,
        status = v.User.Status.Name
    }).ToList();

    Gdview.DataSource = finalClientList;
    Gdview.DataBind();
}

以下是必需的数据库表

User(id,statusid,emailaddress)

client(id,userid,designation,mobilenumber,companyname,contactperson)

status(statusid,statusname)

0 个答案:

没有答案