I have an exchange rate table. I need to get current rate and previous rate and then compare results.
I can get first record using FirstOrDefault
.
When I am using ElementAtOrDefault
, this error shows "The query operator 'ElementAtOrDefault' is not supported". How can I get the second record?
var result = ls. Reverse(). Skip(1). Take(1);
You can get same generated SQL query manually by calling ToString: string sql = committeeMember. ToString(); This overridden method internally calls ObjectQuery.
LINQ to SQL offers an infrastructure (run-time) for the management of relational data as objects. It is a component of version 3.5 of the . NET Framework and ably does the translation of language-integrated queries of the object model into SQL. These queries are then sent to the database for the purpose of execution.
The popular answer is that LINQ is INtegrated with C# (or VB), thereby eliminating the impedance mismatch between programming languages and databases, as well as providing a single querying interface for a multitude of data sources.
You can try this:
var query=data.Skip(1).Take(1);
Take() returns null if the element is not there (so is equivalent to FirstOrDefault()).
If you'd rather an exception was thrown (cos the second element is not there) like First() then use:
Skip(1).Single()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With