View Single Post
  #5 (permalink)  
Old March 16th, 2012, 05:28 AM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
What I was really wondering is it possible to filter the result set that you get back from a data set from LINQ
Sure....

Code:
 
AdventureWorksDataContext dataContext = new AdventureWorksDataContext();
var employees = from emp in dataContext.Employees
                        where e.Gender == 'F'
                        select emp;
 
var fromArizona = from emp in employees 
                         where e.State == "Arizona"
                          select emp;
 
// Or use:
var fromArizona = employees.Where(e => e.State == "Arizona");
 
var fromWyoming  = from emp in employees 
                              where e.State == "Wyoming"
                              select emp;
 
// Or use:
var fromWyoming = employees.Where(e => e.State == "Wyoming");
All of this assumes that the Employee has a State property... Since it queries the local query employees, these queries return Female employees only.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Last edited by Imar; March 16th, 2012 at 05:31 AM..
Reply With Quote