Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get MAX(val) using Entities

Posted on 2013-01-13
6
Medium Priority
?
356 Views
Last Modified: 2013-01-14
How do I get the MAX value from a field in table?

Something like:
Using myContext as new myEntities
    Dim x as integer = (from y in myContext.myTable Select MAX(ID)
End Using
0
Comment
Question by:lippert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 8

Expert Comment

by:deepu chandran
ID: 38773374
Hi,

Try Max function like below, i dont have a system to check below statement

 Dim x as integer = myContext.myTable.Max(p => p.ID)

-- Deepu
0
 
LVL 1

Author Comment

by:lippert
ID: 38773388
'p' needs to be declared. What is it?
0
 
LVL 1

Author Comment

by:lippert
ID: 38773390
What I'm really after here is the equivalent of the SQL statements:
     DECLARE x as int
     Select x = MAX(ID) From myTable
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 11

Expert Comment

by:Mihai Stancescu
ID: 38773423
Hi,

Try it like this:

var max = from mx in myContext.myTable
                  select mx;

int maxValue = max.Max(p=>p.ID);


Regards,
Mishu
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 750 total points
ID: 38773971
Try following

 Dim x as integer = myContext.myTable.Max(Function(x) x.ID)
0
 
LVL 1

Author Closing Comment

by:lippert
ID: 38774333
Thanks for putting me on the right track. Your solution didn't work exactly as posted, but it was a minor change:

Dim x as integer = myContext.myTable.Max(Function(z) z.ID)

Couldn't reuse the x in the function because the compiler complained about the variable being hidden.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question