get max identity value in an entity collection

Posts   
 
    
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 08-Apr-2006 01:30:22   

hiya,

I have an entity collection.I want to find out what is the highest value for a particular field, This field is an identity field, and a primary key in the underlying database.

I see that entityCollection exposes a getDbCount property.I don't think that it exposes a similar property for what I want to do.

Can this be done?

many thanks,

yogi

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 08-Apr-2006 03:00:25   

using Yogi.DAL;
using SD.LLBLGen.Pro.ORMSupportClasses;

//form code snipped out.

private void button4_Click(object sender, EventArgs e)
{
CollectionClasses.TblDeliveryCollection deliveries = new CollectionClasses.TblDeliveryCollection();

int maxValue = (int)deliveries.GetScalar(TblDeliveryFieldIndex.DeliveryId, null,  AggregateFunction.Max);

System.Diagnostics.Trace.WriteLine(maxValue);
}

SQL Generated:


SELECT TOP 1 MAX([dbo].[tblDelivery].[deliveryID]) AS [DeliveryId] FROM [dbo].[tblDelivery] 

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 08-Apr-2006 12:23:43   

sunglasses

cheers Jim, yogi