Solved

Get MAX(val) using Entities

Posted on 2013-01-13
6
344 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
6 Comments
 
LVL 8

Expert Comment

by:deepu chandran
Comment Utility
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
Comment Utility
'p' needs to be declared. What is it?
0
 
LVL 1

Author Comment

by:lippert
Comment Utility
What I'm really after here is the equivalent of the SQL statements:
     DECLARE x as int
     Select x = MAX(ID) From myTable
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 11

Expert Comment

by:Mihai Stancescu
Comment Utility
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 250 total points
Comment Utility
Try following

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

Author Closing Comment

by:lippert
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now