c# - Entity Framework 6, cannot use Ignore method on the property -
currently i'm using asp identity mvc 5.i want remove phonenumber field aspnetusers table, when use add-migration command causes following error.
you cannot use ignore method on property 'phonenumber' on type 'models.dbmodel.user' because type inherits type 'microsoft.aspnet.identity.entityframework.identityuser`
i have read tons of questions on here, of them said have ignore property in base class, however, don't have access base in case.
how can solve problem?
update: when used fluent api inside onmodelcreating method worked, don't want use way separated config class each entity.
below code:
derived entity class
public class user : identityuser { public icollection<comment> comments { get; set; } } config class
public sealed class userconfig : entitytypeconfiguration<user> { public userconfig() { totable("dbo", "users"); ignore(x => x.phonenumber); ignore(x => x.phonenumberconfirmed); } } context class
public class websitecontext : identitydbcontext { public websitecontext() : base("xyz") { } public dbset<comment> comment { get; set; } //public dbset<user> user { get; set; } public static websitecontext create() { return new websitecontext(); } protected override void onmodelcreating(dbmodelbuilder modelbuilder) { base.onmodelcreating(modelbuilder); modelbuilder.configurations.add(new commentconfig()); modelbuilder.configurations.add(new userconfig()); } }
try [notmapped] attribute system.componentmodel.dataannotations.schema might around limitation , has been used ignore enums in mapping, might not want
Comments
Post a Comment