PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

Entity Framework: returning the Entity with the Min() cost

 
 
Markla
Guest
Posts: n/a
 
      4th Sep 2009
Hi,

I'm trying to find an efficient way to search for entity(s) with the lowest
cost from a table of about 2,000 items. Rather than loading all 2,000 items,
which I don't otherwise need, I'm wanting to use an ObjectQuery to return
just the one(s) I need.

I can see a 2-step way of doing this, but want to do it in just one call.

Assuming a table called 'Items', with fields ID, Name, Type and Cost:

float minCost = objectContext.Items.Where(i=>i.Type ==
"SmallType").Min(i=>i.Cost).FirstOrDefault();

ObjectQuery<Item> items = objectContext.Items.Where(z=>z.Cost == minCost);

Is there a way to do this which results in just one call to the database?

Thanks.
+M
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a total cost chart where a component cost is a step cost gvm Microsoft Excel Charting 0 28th Apr 2010 02:10 PM
Entity name must immediately follow the '&' in the entity referenc Jac Microsoft Frontpage 0 21st Jul 2009 10:53 AM
Entity Framework - Reassigning child entity's parent Norm Microsoft ASP .NET 3 6th Jul 2009 08:28 PM
How to relate a SQL based entity with an Object based entity in Entity Framework markla Microsoft ASP .NET 1 6th Oct 2008 10:42 AM
General method to add any entity to its entity list Andrus Microsoft C# .NET 1 24th Sep 2007 05:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:29 PM.