[dba-VB] Using aggregate SQL functions (Count(). Max(), ...) in ADO.NET EF queries in .NET Frame

Shamil Salakhetdinov shamil at smsconsulting.spb.ru
Wed Jun 30 04:51:05 CDT 2010


Hi Gustav --

I just don't know how to write EF LINQ expression to get a Max ID value -
let's say Max ID for Order entity (Order.OrderId) - I guess it should be
easy...

Thank you.

-- Shamil

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Wednesday, June 30, 2010 12:45 PM
To: dba-vb at databaseadvisors.com
Subject: Re: [dba-VB] Using aggregate SQL functions (Count(). Max(),...) in
ADO.NET EF queries in .NET Frame

Hi Shamil

So what you tell is that no ".Max()" is at hand or usable in your
expression? Or am I missing something?

/gustav


>>> shamil at smsconsulting.spb.ru 30-06-2010 07:47 >>>
Hi Gustav --

Thank you for your advice.
Still I have had to use ORDER BY ... DESC to find the last record (this is a
one user application with MS SQL backend) - I cannot find what EF LINQ
expression should be used to get max ID value - I still have to learn a lot
about EF LINQ here...

-- Shamil

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com 
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Friday, June 25, 2010 8:24 PM
To: dba-vb at databaseadvisors.com 
Subject: Re: [dba-VB] Using aggregate SQL functions (Count(). Max(),...) in
ADO.NET EF queries in .NET Framework

Hi Shamil

I have nothing running at the moment on this computer, but isn't it similar
to this (from examples in LinqPad):

For example, the following query will work on the NORTHWND sample database:

from p in Products
let spanishOrders = p.OrderDetails.Where (o => o.Order.ShipCountry ==
"Spain")
where spanishOrders.Any()
orderby p.ProductName
select new
{
	p.ProductName,
	p.Category.CategoryName,
	Orders = spanishOrders.Count(),	
	TotalValue = spanishOrders.Sum (o => o.UnitPrice * o.Quantity)
}

or as shown here:

http://msdn.microsoft.com/en-us/library/cc716738.aspx 

/gustav


>>> shamil at smsconsulting.spb.ru 25-06-2010 11:21 >>>
Hi All,

I can't find is the subj available or not by using LINQ for Entities?
If it's not available do you have good samples' references on how to use
ObjectQuery<...> with custom SQL using aggregare SQL functions?...

Thank you.

-- Shamil



_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com




More information about the dba-VB mailing list