开发者

Linq query not returning records

public tblCustomerDetail GetCustomerDetailsByID(long ID)
        {
            var customer = from c in DataContext.GetTable<tblCustomerDetail>() where c.ID == ID select c;
            return customer as tblCustomerDetail;
        }

DataContext.GetTable() has records in it and after filtering based on ID, there are no records in customer variable, although the record with the ID for which I am searching exists in the returned table.

Please help. 开发者_如何学编程I am new to LINQ.


Your variable customer will be of type IEnumerable<tblCustomerDetail> so when you cast it with the as operator, the result will be null because the types are incompatible.

Try this instead:

public tblCustomerDetail GetCustomerDetailsByID(long ID)
{
    var customer = from c in DataContext.GetTable<tblCustomerDetail>() where c.ID == ID select c;
    return customer.First();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜