EF Code First composite key mapping -
i have 2 tables. user , roles.one user can have meany roles. created table called roleuser. how should implement in code first(i want insert , update operation)
thanks in advance
natively should able declare 2 tables (with properties pointing other) , ef pick on many-to-many relationship (and create intermediary table 2 fk's)
public class user { public int id { get; set; } public string username { get; set; } // user can within multiple roles public icollection<role> roles { get; set; } } public class role { public int id { get; set; } public string name { get; set; } // role can have many users public icollection<user> users { get; set; } }
Comments
Post a Comment