Entity Framework: Using an entity to get a specific result set?http://forums.asp.net/t/1337771.aspx/1?Entity+Framework+Using+an+entity+to+get+a+specific+result+set+Mon, 03 Nov 2008 03:12:55 -050013377712699878http://forums.asp.net/p/1337771/2699878.aspx/1?Entity+Framework+Using+an+entity+to+get+a+specific+result+set+Entity Framework: Using an entity to get a specific result set? Is there anyway to get a specific result set from an entity object? For example, I've got an entity called datUsers. I know I can do this: foreach(var user in datUsers) ... To loop over ALL the records. What if I only want records where active=true? I suspect I could use LINQ, however, if I do that, won't it pull down the entire result set then filter in the web-server's ram instead of using the DB server to do the filtering? Thanks Ryan 2008-10-22T15:04:18-04:002700794http://forums.asp.net/p/1337771/2700794.aspx/1?Re+Entity+Framework+Using+an+entity+to+get+a+specific+result+set+Re: Entity Framework: Using an entity to get a specific result set? <p>&nbsp;If you already populated the entity anything you do is going to get filtered in memory.</p> <p>You could do</p> <p>&nbsp;foreach (var user in datUsers.Where(s =&gt; s.Active == true))<br> {<br> //stuff happens.<br> }<br> </p> 2008-10-23T00:13:25-04:002714776http://forums.asp.net/p/1337771/2714776.aspx/1?Re+Entity+Framework+Using+an+entity+to+get+a+specific+result+set+Re: Entity Framework: Using an entity to get a specific result set? <p>As a side note, using LINQ does indeed filter the results at the DB level.</p> <p>&nbsp;For example: </p> <p>var query = from c in context.Customers where c.customerName == &quot;Roger&quot;;</p> <p>Produces a SQL statement with the where clause stating &quot;where customername = 'Roger'&quot; instead of pulling it all from the DB then doing in-memory filtering. </p> <p>&nbsp;</p> 2008-10-30T14:48:01-04:002719910http://forums.asp.net/p/1337771/2719910.aspx/1?Re+Entity+Framework+Using+an+entity+to+get+a+specific+result+set+Re: Entity Framework: Using an entity to get a specific result set? <p>&nbsp;I agree with scott.<br> </p> 2008-11-03T02:10:44-05:002719999http://forums.asp.net/p/1337771/2719999.aspx/1?Re+Entity+Framework+Using+an+entity+to+get+a+specific+result+set+Re: Entity Framework: Using an entity to get a specific result set? <p>&nbsp;Maybe you need to look up deferred execution.</p> <p>&nbsp;If you have already populated the entity. It's not filtered at DB level.</p> <p>&nbsp;</p> <p>http://blogs.msdn.com/charlie/archive/2007/12/09/deferred-execution.aspx <br> </p> 2008-11-03T03:12:55-05:00