dynamk
asked on
Linq to Entities syntax
Can someone explain to me why the following statement:
var record = _efEntities.Records.LastOr Default();
Throws this error:
System.NotSupportedExcepti on was unhandled
Message="LINQ to Entities does not recognize the method 'EFSchedulerDemo.Resource Last[Resource](System.Linq .IQueryabl e`1[EFSche dulerDemo. Resource]) ' method, and this method cannot be translated into a store expression."
Source="System.Data.Entity "
But I am able to use:
var record = _efEntities.Records.ToList ().LastOrD efault();
How can I get the first or last record without having to call ToList() every time if possible?
var record = _efEntities.Records.LastOr
Throws this error:
System.NotSupportedExcepti
Message="LINQ to Entities does not recognize the method 'EFSchedulerDemo.Resource Last[Resource](System.Linq
Source="System.Data.Entity
But I am able to use:
var record = _efEntities.Records.ToList
How can I get the first or last record without having to call ToList() every time if possible?
ASKER
What I am trying to find out is how to get the entity object Without using the List. The List already works fine but I don't understand why I cannot just use var record =_efEntities.Records.LastO rDefault() without getting an error.
I had this issue as well with different collections, so I sorted out by using Lambda Expression. Try out Lambda Expressions for a try!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Clear and concise. Thank you.
Not a problem, glad I was able to help. ;=)
Hope that should give you the Last and first record out of the List.