0

By googling i have made following select query to take max value of column ID.

 var result = (from rs in db.tradeFiles

                             select (rs.ID)).Max();

Please let me know is this a query is write for taking max value of column ID.

And for taking data out of it in variables i used foreach loop in following manner which is also not working.

foreach(var item in result)
           {

           }

Please let me know what is the mistake and what is the correct way to pull out the data out of select query.

3 Answers 3

4

Result is the value itself, just use it, there is no need to iterate over it. If for example rs.ID column is int, then result will be the int.

Sign up to request clarification or add additional context in comments.

2 Comments

If var result = (from rs in db.tradeFiles select (rs.ID)) this is the query, then how should i pull the individual ID value out of it?
@freelancer from ... select construct always return a list or results (IEnumerable to be exact). There are methods that can narrow down that list to 1 item, like First and Single.
1

Enumerable.Max can't be enumerated, it returns the value you're looking for.

1 Comment

If var result = (from rs in db.tradeFiles select (rs.ID)) this is the query, then how should i pull the individual ID value out of it?
0

in result you will get one int value.because you are taking max value of the column. it will give one single result.if you want to take some specific id value ,you just make one where condition and select that value.like

(from rs in db.tradeFiles
where rs.id==1
select (rs.Name)); something like this..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.