c# - Add a column to join table EF6 -


i'm working ef6 code first database migrations , i'm beginner. i'm building web api. in model plan have user (identity framework) , location class many many relationship. ef6 automatic created table locationuser want extend table columns. best way that.

of course i've searched solutions i'm not sure best way go.

i can edit last migration method , add columns want i'm not sure if best way. in opinion creating new model class manually possibility.

could tell me best way , elaborate why?

user.cs

public class user : identityuser {     public virtual icollection<location> locations { get; set; }     // other code identity framework } 

location.cs

public class location {     public int id { get; set; }     public string name { get; set; }     public string description { get; set; }     public double lat { get; set; }     public double lng { get; set; }      public virtual icollection<user> users{ get; set; } } 

you can create own userlocation class below.

public class userlocation {     public int id { get; set; }     public location location { get; set; }     public user user { get; set; }     //extra fields want can go here } 

then in user , location classes change link use userlocation class.

example:

public class user : identityuser {     public virtual icollection<userlocation> locations { get; set; }     // other code identity framework } 

can add entitytypeconfigurations classes enforce many-many, below 1 user

public class userconfiguration : entitytypeconfiguration<user> {     public userconfiguration()     {         haskey(x => x.id);         hasmany(x => x.locations);     } } 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -