First I use VS 2010 and Entity Framework code (version 6). I have two entities, each in its own context, and I want to create a one-to-many relationship between them.
Context 1 has the following object:
public class MyTrust { public int MyTrustID { get; set; } public string MyTrustName { get; set; } }
and context 2 has the following object:
public class MyLocation { public int MyLocationID { get; set; } public int MyTrustID { get; set; } public virtual MyTrust MyTrust { get; set; } }
with the following Fluent API
modelBuilder.Entity<MyLocation>() .HasRequired(m => m.MyTrust);
The migration file for Context 2 contains the correct keys, but also creates a new table for MyTrust
, which already exists in a different context.
I know that I can edit the migration file, but this is not a solution.
My question is: how to stop creating a second MyTrust
table.
UPDATE
There was a major flaw in that I inserted the wrong code in context 2. Now fixed. Apologies
source share