Last active
April 7, 2017 12:16
-
-
Save owen2/5dff481ad03e40161e4b7ad942f032ec to your computer and use it in GitHub Desktop.
EF Code First Association Table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//From Model Builder | |
modelBuilder.Entity<ThisTable>(). | |
HasMany(c => c.OtherTable). | |
WithMany(p => p.AssocTable). | |
Map( | |
m => | |
{ | |
m.MapLeftKey("ThisId"); | |
m.MapRightKey("OtherId"); | |
m.ToTable("AssocTable"); | |
}); | |
//From entity configuration class | |
HasMany(p => p.OtherTable).WithMany().Map(assoc => | |
{ | |
assoc.MapLeftKey("ThisId"); | |
assoc.MapRightKey("OtherId"); | |
assoc.ToTable("MakeUpANameForYourNewAssocTable"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment