Couldn't getting any records.Throwing an error :
An exception of type 'System.NullReferenceException' occurred in DAL.dll but was not handled in user code Additional information: Object reference not set to an instance of an object.
Considering the following records:
Id No createdDate Extension
--------------------------------------------------
1 9000 1990 10
2 9000 1990 11
3 9000 2000 12
4 9849 2001 1
5 9849 2002 2
6 9700 2010 4
var res = from cust in Customers
group cust by cust.No
into groups
select groups.OrderByDescending(p => p.Id).FirstOrDefault();
where as this same concept applying in Controller action methode like below.Then not getting any null error, getting records as per my requirement.
var result = from refC in _objRefCustomerBS.GetAllRefCustomer()
group refC by refC.MobileNo into grp
select grp.OrderByDescending(g => g.cuRefID).FirstOrDefault();
I want to group by based on the No
field and sort by Id
and get all fields from the last record of group similar to these records:
Id No createdDate Extension
-------------------------------------------------
3 9000 2000 12
5 9849 2002 2
6 9700 2010 4