?
Solved

Visual Studio - LINQ to SQL Class - 1 to Many - How to return children

Posted on 2009-12-29
3
Medium Priority
?
305 Views
Last Modified: 2013-11-11
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
0
Comment
Question by:JElster
  • 2
3 Comments
 
LVL 12

Expert Comment

by:kumar754
ID: 26138341
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
 
LVL 1

Author Comment

by:JElster
ID: 26138551
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
 
LVL 12

Accepted Solution

by:
kumar754 earned 600 total points
ID: 26175697
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month16 days, 18 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question