Gentlemen, I have a category class, which must be entered by registered users.
My relationship idea is 1 user can have multiple categories.
I have my projects separated but related to each other according to the image below
I tried to create the relationship between Identity and category with the following code
public class Categoria
{
public Guid Id { get; set; }
public string Nome { get; set; }
public virtual TipoCategoria TipoCategoria { get; set; }
public Usuario.Usuario Usuario { get; set; }
public Guid IdUsuario { get; set; }
}
public class Usuario : ApplicationUser
{
public Usuario()
{
Categorias = new List<Categoria.Categoria>();
}
public virtual ICollection<Categoria.Categoria> Categorias { get; set; }
}
But when I give Update-Database -Force -Verbose presents the following error
PM> Update-Database -Force -Verbose
Using StartUp project 'PoupMe.Services.WebAPI.Mobile'.
Using NuGet project 'PoupMe.Data'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:
PoupMe.Data.Context.ApplicationUserLogin: : EntityType 'ApplicationUserLogin' has no key defined. Define the key for this EntityType.
PoupMe.Data.Context.ApplicationUserRole: : EntityType 'ApplicationUserRole' has no key defined. Define the key for this EntityType.
Categoria_Usuario_Target_Categoria_Usuario_Source: : The types of all properties in the Dependent Role of a referential constraint must be the same as the corresponding property types in the Principal Role. The type of property 'IdUsuario' on entity 'Categoria' does not match the type of property 'Id' on entity 'Usuario' in the referential constraint 'Categoria_Usuario'.
ApplicationUserLogins: EntityType: EntitySet 'ApplicationUserLogins' is based on type 'ApplicationUserLogin' that has no keys defined.
ApplicationUserRoles: EntityType: EntitySet 'ApplicationUserRoles' is based on type 'ApplicationUserRole' that has no keys defined.
at System.Data.Entity.Core.Metadata.Edm.EdmModel.Validate()
at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy'2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.LazyInternalContext.get_ModelBeingInitialized()
at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
at System.Data.Entity.Utilities.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w)
at System.Data.Entity.Utilities.DbContextExtensions.GetModel(Action'1 writeXml)
at System.Data.Entity.Utilities.DbContextExtensions.GetModel(DbContext context)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, Boolean calledByCreateDatabase)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
One or more validation errors were detected during model generation:
PoupMe.Data.Context.ApplicationUserLogin: : EntityType 'ApplicationUserLogin' has no key defined. Define the key for this EntityType.
PoupMe.Data.Context.ApplicationUserRole: : EntityType 'ApplicationUserRole' has no key defined. Define the key for this EntityType.
Categoria_Usuario_Target_Categoria_Usuario_Source: : The types of all properties in the Dependent Role of a referential constraint must be the same as the corresponding property types in the Principal Role. The type of property 'IdUsuario' on entity 'Categoria' does not match the type of property 'Id' on entity 'Usuario' in the referential constraint 'Categoria_Usuario'.
ApplicationUserLogins: EntityType: EntitySet 'ApplicationUserLogins' is based on type 'ApplicationUserLogin' that has no keys defined.
ApplicationUserRoles: EntityType: EntitySet 'ApplicationUserRoles' is based on type 'ApplicationUserRole' that has no keys defined.