c# - Add properties to User table using asp identity -
ok, want add properties user table created asp identity.
so read , found out can doing this:
public class applicationuser : identityuser { public string firstname { get; set; } public string lastname { get; set; } public string gender { get; set; } public int age { get; set; } public ilist<blog> blogs { get; set; } public async task<claimsidentity> generateuseridentityasync(usermanager<applicationuser> manager) { // note authenticationtype must match 1 defined in cookieauthenticationoptions.authenticationtype var useridentity = await manager.createidentityasync(this, defaultauthenticationtypes.applicationcookie); // add custom user claims here return useridentity; } }
so properties added table dbo.aspnetusers , not users table. why?
so thought maybe places properties there can use them in same dbset added code:
public class travelcontext : dbcontext { static travelcontext() { system.data.entity.database.setinitializer<travelcontext>(new createdatabaseifnotexists<travelcontext>()); } public travelcontext() : base("name=traveldb2") { } public dbset<blog> blog { get; set; } public dbset<continent> continent { get; set; } public dbset<country> country { get; set; } public dbset<destination> destinations { get; set; } public dbset<travel> travel { get; set; } public dbset<identityuser> user { get; set; } }
but doesn't me. still can't example firstname user can reach properties users table.
so how add properties right table , how add them in context can use them using ef? edit:
modelbuilder.entity<identityuser>().totable("users", "dbo"); modelbuilder.entity<identityuserrole>().totable("userroles", "dbo"); modelbuilder.entity<identityrole>().totable("roles", "dbo"); modelbuilder.entity<identityuserclaim>().totable("userclaims", "dbo"); modelbuilder.entity<identityuserlogin>().totable("userlogin", "dbo");
eidt new context:
public class travelcontext : identitydbcontext<applicationuser> { static travelcontext() { system.data.entity.database.setinitializer<travelcontext>(new createdatabaseifnotexists<travelcontext>()); } public static travelcontext create() { return new travelcontext(); } public travelcontext() : base("name=traveldb2") { } public dbset<blog> blog { get; set; } public dbset<continent> continent { get; set; } public dbset<country> country { get; set; } public dbset<destination> destinations { get; set; } public dbset<travel> travel { get; set; } public dbset<identityuser> user { get; set; } protected override void onmodelcreating(dbmodelbuilder modelbuilder) { base.onmodelcreating(modelbuilder); modelbuilder.entity<identityuser>().totable("users", "dbo"); modelbuilder.entity<identityuserrole>().totable("userroles", "dbo"); modelbuilder.entity<identityrole>().totable("roles", "dbo"); modelbuilder.entity<identityuserclaim>().totable("userclaims", "dbo"); modelbuilder.entity<identityuserlogin>().totable("userlogin", "dbo"); modelbuilder.entity<blog>().hasmany(a => a.users); modelbuilder.entity<applicationuser>().hasmany(a => a.blogs); } }
so adds id of blog user table , id of user blog entity added hasmany should create many-to-many relation?
Comments
Post a Comment