Database Reference
In-Depth Information
foreach (var worker in context.Workers)
{
Console.WriteLine("\n{0}'s tasks:", worker.Name);
foreach (var wt in worker.WorkerTasks)
{
Console.WriteLine("\t{0}", wt.Task.Title);
}
}
}
The code in Listing 6-3 produces the following output:
Workers and Their Tasks
=======================
Jim's tasks:
Fold Envelopes
Mail Letters
Sara's tasks:
Buy Envelopes
6-3. Modeling a Many-to-Many, Self-Referencing Relationship
Problem
You have a table with a many-to-many relationship with itself, and you want to model this table and relationship.
Solution
Let's say that you have a table that has relationship to itself using a link table, as shown in Figure 6-4 .
Figure 6-4. A table with a many-to-many relationship to itself
To create a model, do the following:
1.
Create a new class in your project that inherits from DbContext.
2.
Add a Product POCO entity class to your project using the code in Listing 6-4.
 
Search WWH ::




Custom Search