Data Platform Developer Center >
Data Platform Development Forums
>
ADO.NET Entity Framework and LINQ to Entities
>
How have it works the EntityColletion?
How have it works the EntityColletion?
- HiI my project, I have an entity that have an Entity Collection and, I want to filter the colletion.For example, I do a LINQ that brings an customer and this customer have an EntityColletion with all his orders this customer. I want to filter something orders, Is this possible?Thanks in Advance.
Marcos Aguiar Jr - Brazil
Answers
- Hi Marcos,
I hope I understood your question correctly.
If you have a handle on the customer, you can issue a query as follows to filter some of the orders
Customer cust = YourMethodToGetACustomer()
foreach (Order o in cust.Orders.Where(x => x.OrderId > 0))
{
//do something with the order
}
You can use the followng link to get more information on using LINQ to Entities:
http://msdn.microsoft.com/en-us/library/bb738458.aspx
Regards,
Akhil Karkera (MSFT)- Marked As Answer byMarcos Aguiar Jr Friday, November 06, 2009 3:16 PM
- Hi Marcos,
If you want to get some customers records and filtered collection of the orders belonging to those customers, you can have a query like this:
var query = from c in dc.Customers where c.Active == true //some condition select new { c, orders = from o in c.Orders where o.OrderDate > DateTime.Parse("2009-10-01") //filter orders of each customer on some condition select o }; var customers = query.AsEnumerable().Select(q => q.c); //now customers will have selected customers and their associated filtered orders
For more details, have a look at this post: How to do a Conditional Include
Regards,
Syed Mehroz Alam
My Blog | My Articles- Marked As Answer byMarcos Aguiar Jr Friday, November 06, 2009 3:15 PM
All Replies
- Hi Marcos,
I hope I understood your question correctly.
If you have a handle on the customer, you can issue a query as follows to filter some of the orders
Customer cust = YourMethodToGetACustomer()
foreach (Order o in cust.Orders.Where(x => x.OrderId > 0))
{
//do something with the order
}
You can use the followng link to get more information on using LINQ to Entities:
http://msdn.microsoft.com/en-us/library/bb738458.aspx
Regards,
Akhil Karkera (MSFT)- Marked As Answer byMarcos Aguiar Jr Friday, November 06, 2009 3:16 PM
- Hi Marcos,
If you want to get some customers records and filtered collection of the orders belonging to those customers, you can have a query like this:
var query = from c in dc.Customers where c.Active == true //some condition select new { c, orders = from o in c.Orders where o.OrderDate > DateTime.Parse("2009-10-01") //filter orders of each customer on some condition select o }; var customers = query.AsEnumerable().Select(q => q.c); //now customers will have selected customers and their associated filtered orders
For more details, have a look at this post: How to do a Conditional Include
Regards,
Syed Mehroz Alam
My Blog | My Articles- Marked As Answer byMarcos Aguiar Jr Friday, November 06, 2009 3:15 PM


