简体   繁体   English

模式中的每个类型名称都必须是唯一的。 代码优先

[英]Each type name in a schema must be unique. Code first

I'm trying to update my database Code first but I get this error after Run add-migration command 我正在尝试先更新数据库代码,但在运行add-migration命令后出现此错误

One or more validation errors were detected during model generation:

ServicioTest.ErrorDispositivo: Name: Each type name in a schema must be 
unique. Type name 'ErrorDispositivo' is already defined.

I've tried a lot of possible solutions: 我尝试了很多可能的解决方案:

  • Clean and rebuild 清理并重建
  • Delete Migrations folder and tables in database 删除数据库中的迁移文件夹和表
  • Change connection string name 更改连接字符串名称
  • Delete bin folder and then rebuild 删除bin文件夹,然后重建

But doesn't work. 但是不起作用。

My data is 我的数据是

public class ModeloDatos : DbContext
{

    public ModeloDatos()
        : base("name=ModeloDatos")
    {
    }
    public virtual DbSet<Dispositivos> Dispositivos { get; set; }
    public virtual DbSet<Solicitud> Solicitudes { get; set; }
    public virtual DbSet<Aplicacion> Aplicaciones { get; set; }
    public virtual DbSet<Log> Logs { get; set; }
    public virtual DbSet<ErrorDispositivo> ErroresDispositivo { get; set; }
    public virtual DbSet<FormatoTemplate> FormatosTemplate { get; set; }
}

[Table("Dispositivos")]
public class Dispositivos
{
    [Key]
    public string DispositivoID { get; set; }

    //propiedad de navegacion
    public virtual ICollection<Solicitud> Solicitudes { get; set; }
}



[Table("Solicitudes")]
public class Solicitud
{
    //primary key
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int SolicitudID { get; set; }
    public DateTime Fecha { get; set; }
    public string Ip { get; set; }


    public string DispositivoID { get; set; }
    [ForeignKey("DispositivoID")]
    public virtual Dispositivos Dispositivo { get; set; }


    public Respuesta DatosRespuesta { get; set; }


}


[Table("Aplicaciones")]
public class Aplicacion
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    public string Usuario { get; set; }

    [DataType(DataType.Password)]
    public string Clave { get; set; }

    public Guid Codigo { get; set; }

    public bool Habilitado { get; set; }

}

[Table("Logs")]
public class Log
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }
    public string Descripcion { get; set; }
    public string StackTrace { get; set; }
}

[ComplexType]
public class Respuesta
{

    public string Codigo { get; set; }
    [ForeignKey("Codigo")]
    public virtual ErrorDispositivo TipoErrorDispositivo { get; set; }


    public string Mensaje { get; set; }
    public string FingerPrint1 { get; set; }
    public string FingerPrint2 { get; set; }


}

[Table("ErrorDispositivos")]
public class ErrorDispositivo
{
    [Key]
    public string Codigo { get; set; }
    public string Descripcion { get; set; }
}


[Table("FormatoTemplates")]
public class FormatoTemplate
{
    [Key]
    public int Codigo { get; set; }
    public string Formato { get; set; }
}

How can I solve this ? 我该如何解决?

I believe the issue will be with the complex type and 我相信问题将出在复杂的类型和

public virtual ErrorDispositivo TipoErrorDispositivo { get; set; }

You cannot have navigation properties within the complex type. 您不能在复杂类型内具有导航属性。 This should be pulled out to the entities that need this relationship. 这应该拉到需要此关系的实体。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (21,6):错误0019:类型中的每个属性名称都必须是唯一的。 - (21,6) : error 0019: Each property name in a type must be unique. 架构中的每个类型名称必须是唯一的 - Each type name in a schema must be unique 如何防止出现错误“ Id:名称:类型中的每个属性名称都必须是唯一的。 属性名称“ Id”已经定义。” - How to prevent error “Id: Name: Each property name in a type must be unique. Property name 'Id' is already defined.” EF 4.1 Code First:类型中的每个属性名称必须是查找表关联上的唯一错误 - EF 4.1 Code First: Each property name in a type must be unique error on Lookup Table association 每个表中的列名必须唯一。 表“ HumanCustomers”中的列名“ LastName”已多次指定 - Column names in each table must be unique. Column name 'LastName' in table 'HumanCustomers' is specified more than once EntityContainer 名称必须是唯一的。 已定义名称为“Entities”的 EntityContainer - The EntityContainer name must be unique. An EntityContainer with the name 'Entities' is already defined EF 4:System.Data.Entity.Edm.EdmEntityType:名称:模式中的每个类型名称都必须是唯一的 - EF 4: System.Data.Entity.Edm.EdmEntityType: Name: Each type name in a schema must be unique 每个表中的列名必须唯一。 表Entity1&#39;中的列名&#39;Id&#39;被多次指定 - Column names in each table must be unique. Column name 'Id' in table Entity1' is specified more than once 每个表中的列名必须唯一。 表“ UserLogins”中的列名“ department_Id”已多次指定 - Column names in each table must be unique. Column name 'department_Id' in table 'UserLogins' is specified more than once 类型中的每个属性名称必须唯一 - Each property name in a type must be unique
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM