JElster
asked on
Visual Studio - LINQ to SQL Class - 1 to Many - How to return children
Hi..
I have LINQ to SQL class I created in the Visual Studio LINQ to SQL designer. It's simple 1 to many. Like customers to orders.
I created a 1 to many Association in the designer. My class that is generated for Customers contains an Entity property for Orders.
When I run my GetCustomersQuery() - the data is returned but the Entity property with the Orders is empty. How do return the Customers with the corresponding Orders?
thanks
I have LINQ to SQL class I created in the Visual Studio LINQ to SQL designer. It's simple 1 to many. Like customers to orders.
I created a 1 to many Association in the designer. My class that is generated for Customers contains an Entity property for Orders.
When I run my GetCustomersQuery() - the data is returned but the Entity property with the Orders is empty. How do return the Customers with the corresponding Orders?
thanks
ASKER
Hi.. My query looks like this.. how do I include the Orders.. thanks again
var query = from c in DS.GetCustomersQuery()
orderby c.name
select c;
LoadOperation<Customers> lo = DS.Load(query);
var query = from c in DS.GetCustomersQuery()
orderby c.name
select c;
LoadOperation<Customers> lo = DS.Load(query);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
activeLoad.LoadWith<Custom
context.LoadOptions = loadOptions;
var customers = from customer in context.customers
select customer;
// this will all Orders (if exists for a customer) and in your code you can access ordres ust by using
Customer[] allCustomers = GetCustomerQuery();
foreach (Customer c in allCustomers)
{
if (c.Order != null) int orderId = c.Order.OrderID;
}