asp.net mvc - AspNet Identity 2.0 Email and UserName duplication -
my current asp.net mvc 5 project mandates email address username. want upgrade aspnet identity v1.0 v2.0 leverage new features (see here).
however, aspnet identity v2.0 adds email separate column users table , adds corresponding property identityuser class.
i don't want duplicate username new email column. how can map email property of identityuser use existing username column & property? possible ignore email property , skip adding column in users table? has tried this?
please share.
update
this identity 2.0 limitation. cannot ignore email property or leave null. of identity functionality not work. :(
you can try 1 of these:
try ignore either overriding
email
property inuser
class , unmapping or using fluent api.public class applicationuser : identityuser { // .... [notmapped] public override string email { get; set; } }
or
protected override void onmodelcreating(dbmodelbuilder modelbuilder) { modelbuilder.entity<applicationuser>().ignore(u => u.email); }
when register user make sure populate
email
username
public async task<actionresult> register(registerviewmodel model) { if (modelstate.isvalid) { var user = new applicationuser { username = model.email, email = model.email }; // ... } }
of course, can ignore email
column if you're not going use it, since allows nulls, it'll sitting in aspnetusers
table bunch of nulls, not best approach remember ignoring might lose new features asp.net identity 2 might offer might want use.
note i'm not sure if option number 1 work on email
property since it's used on place in new identity code. worth try though. know that's how can rid of other columns if don't need them. happen use new email
property/column haven't tried it.
not sure if helps you, thought i'd share in case.
Comments
Post a Comment