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();
}
精彩评论