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
LVL 1
JElsterAsked:
Who is Participating?
 
kumar754Commented:
DataLoadOptions loadOptions = new DataLoadOptions();
activeLoad.LoadWith<Customers>(c => c.Orders);

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;
}

0
 
JElsterAuthor Commented:
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);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.