?
Solved

Get MAX(val) using Entities

Posted on 2013-01-13
6
Medium Priority
?
354 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
Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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)…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

762 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