[英]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: 我尝试了很多可能的解决方案:
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.