Entity Framework CTP5 (code first) Modeling - lookup tables

Assume the following table structure:

Tables:

**Tasks** taskID int PK taskName varchar **Resources** resourceID int PK resourceName varchar **Assignments** assignmentID int PK taskID int FK resourceID int FK 

In the assignment table, a task with a resource assigned to it is defined. Is it possible to correlate this structure with the model builder so that I do not have to create the poco Assignment class - hiding part of the basic data structure?

i.e:.

 public class Task { public int taskID { get; set; } public string taskName { get; set; } public virtual ICollection<Resource> resourceItems { get; set; } } public class Resource { public int resourceID { get; set; } public string resourceName { get; set; } } 

How can I use model builder to map tasks to resources without creating an assignment poco class?

+6
entity-framework data-modeling ef-code-first code-first entity-framework-ctp5
source share
1 answer

Here is an article about this same .

Edit, I do not have an IDE in front of me, so this may not be the exact "last" syntax, but it should start:

 modelBuilder.Entity<Task>().HasMany(a => a.Resources).WithMany(b => b.Tasks).Map(m => { m.MapLeftKey(a => a.TaskId,"taskId"); m.MapRightKey(b => b.ResourceId, "resourceId"); m.ToTable("Assignments"); }); 
+3
source share

All Articles