public class Identitydbcontext:dbcontext { Public Identitydbcontext (): This ("DefaultConnection") { } protected override void Onmodelcreating (Dbmodelbuilder modelBuilder) { if (ModelBuilder = = null) { throw new ArgumentNullException ("ModelBuilder"); } entitytypeconfiguration<tuser> configuration = modelbuilder.entity<tuser> (). ToTable ("Aspnetusers"); Configuration. hasmany<tuserrole> (U = u.roles). Withrequired (). hasforeignkey<tkey> (ur = ur). USERID); Indexattribute Indexattribute = new Indexattribute ("Usernameindex") { IsUnique = True }; Configuration. Property ((Expression<func<tuser, string>>) (U = u.username)). IsRequired (). Hasmaxlength (0x100). Hascolumnannotation ("Index", New Indexannotation (Indexattribute)); Configuration. Property ((Expression<func<tuser, string>>) (U = u.email)). Hasmaxlength (0x100); Modelbuilder.entity<tuserrole> (). Haskey (r = new {UserId = R.userid, Roleid = R.roleid}). ToTable ("Aspnetuserroles"); entitytypeconfiguration<trole> Configuration2 = modelbuilder.entity<trole> (). ToTable ("Aspnetroles"); Indexattribute attribute2 = new Indexattribute ("Rolenameindex") { IsUnique = True }; Configuration2. Property ((Expression<func<trole, string>>) (r = r.name)). IsRequired (). Hasmaxlength (0x100). Hascolumnannotation ("Index", New Indexannotation (Attribute2)); Configuration2. Hasmany<tuserrole> (r = r.users). Withrequired (). hasforeignkey<tkey> (ur = ur). Roleid); } Public virtual idbset<trole> Roles {get; set;} Public virtual idbset<tuser> Users {get; set;} } |