entity framework - The EntitySet 'AspNetRoles' with schema 'dbo' and table 'AspNetRoles' was already defined. Each EntitySet must refer to a unique schema and table -
error in migrations :
pm> enable-migrations checking if context targets existing database... system.data.entity.modelconfiguration.modelvalidationexception: 1 or more validation errors detected during model generation:
aspnetroles: name: entityset 'aspnetroles' schema 'dbo' , table 'aspnetroles' defined. each entityset must refer unique schema , table.
at system.data.entity.core.metadata.edm.edmmodel.validate() @ system.data.entity.dbmodelbuilder.build(dbprovidermanifest providermanifest, dbproviderinfo providerinfo) @ system.data.entity.dbmodelbuilder.build(dbconnection providerconnection) @ system.data.entity.internal.lazyinternalcontext.createmodel(lazyinternalcontext internalcontext) @ system.data.entity.internal.retrylazy
2.getvalue(tinput input) @ system.data.entity.internal.lazyinternalcontext.initializecontext()
1.isidentityv1schema(dbcontext db) @ microsoft.aspnet.identity.entityframework.identitydbcontext
@ system.data.entity.internal.internalcontext.createobjectcontextforddlops() @ system.data.entity.database.exists() @ microsoft.aspnet.identity.entityframework.identitydbcontext1..ctor(string nameorconnectionstring, boolean throwifv1schema) @ microsoft.aspnet.identity.entityframework.identitydbcontext
1..ctor(string nameorconnectionstring) @ apk.model.apkentities..ctor() in c:\users\administrator\documents\visual studio 2013\projects\apk\apk.data\apkentities.cs:line 10 --- end of stack trace previous location exception thrown --- @ system.runtime.exceptionservices.exceptiondispatchinfo.throw() @ system.data.entity.infrastructure.dbcontextinfo.createinstance() @ system.data.entity.infrastructure.dbcontextinfo..ctor(type contexttype, dbproviderinfo modelproviderinfo, appconfig config, dbconnectioninfo connectioninfo, func`1 resolver) @ system.data.entity.migrations.dbmigrator..ctor(dbmigrationsconfiguration configuration, dbcontext userscontext, databaseexistencestate existencestate) @ system.data.entity.migrations.dbmigrator..ctor(dbmigrationsconfiguration configuration) @ system.data.entity.migrations.design.migrationscaffolder..ctor(dbmigrationsconfiguration migrationsconfiguration) @ system.data.entity.migrations.design.toolingfacade.scaffoldrunner.run() @ system.appdomain.docallback(crossappdomaindelegate callbackdelegate) @ system.appdomain.docallback(crossappdomaindelegate callbackdelegate)
@ system.data.entity.migrations.design.toolingfacade.run(baserunner runner) @ system.data.entity.migrations.design.toolingfacade.scaffoldinitialcreate(string language, string rootnamespace) @ system.data.entity.migrations.enablemigrationscommand.<>c__displayclass2.<.ctor>b__0() @ system.data.entity.migrations.migrationsdomaincommand.execute(action command) 1 or more validation errors detected during model generation:aspnetroles: name: entityset 'aspnetroles' schema 'dbo' , table 'aspnetroles' defined. each entityset must refer unique schema , table.
why error occur?
i need change in identityrole , identityuser.
public class apkentities : identitydbcontext<applicationuser> { public apkentities () : base("apkentities") { } public virtual void commit() { base.savechanges(); } protected override void onmodelcreating(dbmodelbuilder modelbuilder) { base.onmodelcreating(modelbuilder); modelbuilder.conventions.remove<includemetadataconvention>(); modelbuilder.configurations.add(new aspnetroleconfiguration()); modelbuilder.configurations.add(new aspnetuserconfiguration()); } } public class aspnetroleconfiguration : entitytypeconfiguration<applicationrole> { public aspnetroleconfiguration(string schema = "dbo") { totable(schema + ".aspnetroles"); haskey(x => x.id); property(x => x.id).hascolumnname("id").isrequired().hasmaxlength(128).hasdatabasegeneratedoption(databasegeneratedoption.none); property(x => x.name).hascolumnname("name").isrequired().hasmaxlength(256); property(x => x.namefa).hascolumnname("namefa").isrequired().hasmaxlength(50); property(x => x.description).hascolumnname("description").isoptional().hasmaxlength(250); property(x => x.isactivated).hascolumnname("isactivated").isrequired(); } } public class aspnetuserconfiguration : entitytypeconfiguration<applicationuser> { public aspnetuserconfiguration(string schema = "dbo") { totable(schema + ".aspnetusers"); haskey(x => x.id); property(x => x.id).hascolumnname("id").isrequired().hasmaxlength(128).hasdatabasegeneratedoption(databasegeneratedoption.none); property(x => x.email).hascolumnname("email").isoptional().hasmaxlength(256); property(x => x.phonenumberconfirmed).hascolumnname("phonenumberconfirmed").isoptional(); property(x => x.firstname).hascolumnname("firstname").isoptional(); property(x => x.lastname).hascolumnname("lastname").isoptional(); property(x => x.datecreated).hascolumnname("datecreated").isrequired(); property(x => x.passwordhash).hascolumnname("passwordhash").isoptional(); property(x => x.securitystamp).hascolumnname("securitystamp").isoptional(); property(x => x.username).hascolumnname("username").isrequired().hasmaxlength(256); } } public class applicationrole : identityrole { public string description { get; set; } public string namefa { get; set; } public bool isactivated { get; set; } } public class applicationuser : identityuser { public applicationuser() { datecreated = datetime.now; lf_favoraiteteam = new collection<lf_favoraiteteam>(); } public string firstname { get; set; } public string lastname { get; set; } public datetime datecreated { get; set; } public datetime? lastlogintime { get; set; } public bool? isactivated { get; set; } public virtual icollection<lf_favoraiteteam> lf_favoraiteteam { get; set; }
}
try defining applicationuser , applicationrole dbsets explicitly in apkentities context , remove properties in identityrole , identityuser objects. defined inheriting identitydbcontext.
Comments
Post a Comment