Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# (21,6):错误0019:类型中的每个属性名称必须是唯一的。_C#_Entity Framework_Ef Code First - Fatal编程技术网

C# (21,6):错误0019:类型中的每个属性名称必须是唯一的。

C# (21,6):错误0019:类型中的每个属性名称必须是唯一的。,c#,entity-framework,ef-code-first,C#,Entity Framework,Ef Code First,您好,我知道这已经被安静地问了好几次,虽然我阅读了其他用户的答案,但我似乎仍然无法理解,在尝试先用EF代码初始化数据库后,我遇到了这个错误: (21,6):错误0019:类型中的每个属性名称必须是唯一的。已定义属性名称“AlumnoID” 以下是我的项目结构: 下面是我得到错误的poco类的配置: public class AlumnosConfiguracion : EntityTypeConfiguration<tblAlumnos> { public Al

您好,我知道这已经被安静地问了好几次,虽然我阅读了其他用户的答案,但我似乎仍然无法理解,在尝试先用EF代码初始化数据库后,我遇到了这个错误:

(21,6):错误0019:类型中的每个属性名称必须是唯一的。已定义属性名称“AlumnoID”

以下是我的项目结构:

下面是我得到错误的poco类的配置:

   public class AlumnosConfiguracion : EntityTypeConfiguration<tblAlumnos>
    {
    public AlumnosConfiguracion()
    {
        this.HasKey(p => p.AlumnoID);
       // this.Property(p => p.AlumnoID).HasColumnOrder(0);


        this.Property(p => p.Matricula).IsRequired();
        this.Property(p => p.ApellidoPaterno).HasMaxLength(120).IsRequired();
        this.Property(p => p.ApellidoMaterno).HasMaxLength(120).IsRequired();
        this.Property(p => p.Nombres).HasMaxLength(25).IsRequired();
        this.Property(p => p.Edad).IsRequired();
        this.Property(p => p.Sexo).HasMaxLength(10).IsRequired();
        this.Property(p => p.FechaNacimiento).HasMaxLength(20).IsRequired();
        this.Property(p => p.Nacionalidad).HasMaxLength(25).IsRequired();
        this.Property(p => p.Telefono).HasMaxLength(25).IsOptional();
        this.Property(p => p.DomicilioID).IsOptional();
        this.Property(p => p.Activo).IsRequired();

        //Relacion direccion a alumnos, un alumno una direccion, una direccion muchos alumnos.
        this.HasRequired(a => a.objDomicilio)
            .WithMany(d => d.alumnos)
            .HasForeignKey(a => a.DomicilioID)
            .WillCascadeOnDelete(false);
        //Relacion Plantel a alumnos, donde un planetel puede tener muchos alumnos, pero un alumno un plantel.
        this.HasRequired(a => a.objPlantel)
            .WithMany(p => p.alumnos)
            .HasForeignKey(a => a.PlantelID)
            .WillCascadeOnDelete(false);
    }
}
公共类校友配置:EntityTypeConfiguration
{
公共校友配置()
{
this.HasKey(p=>p.AlumnoID);
//this.Property(p=>p.AlumnoID).HasColumnOrder(0);
this.Property(p=>p.Matricula).IsRequired();
this.Property(p=>p.apellidopterno).HasMaxLength(120).IsRequired();
this.Property(p=>p.ApellidoMaterno).HasMaxLength(120).IsRequired();
this.Property(p=>p.Nombres).HasMaxLength(25.IsRequired();
this.Property(p=>p.Edad).IsRequired();
this.Property(p=>p.Sexo).HasMaxLength(10.IsRequired();
this.Property(p=>p.FechaNacimiento).HasMaxLength(20.IsRequired();
this.Property(p=>p.Nacionalidad).HasMaxLength(25.IsRequired();
this.Property(p=>p.Telefono).HasMaxLength(25.IsOptional();
this.Property(p=>p.domincilioid).IsOptional();
this.Property(p=>p.Activo).IsRequired();
//关系指导a校友、联合国校友、联合国校友。
this.HasRequired(a=>a.objDomicilio)
.有许多(d=>d.校友)
.HasForeignKey(a=>a.domincilioid)
.WillCascadeOnDelete(假);
//有关Plantel a校友的信息,请参阅Plantel puede tener muchos校友,以及Plantel校友。
this.HasRequired(a=>a.objPlantel)
.有许多(p=>p.校友)
.HasForeignKey(a=>a.PlantelID)
.WillCascadeOnDelete(假);
}
}
下面是db上下文类:

命名空间GestionAlumnos.Contexto { 公共类校友数据库:DbContext { //sqlserver中datos sea igual基地的建造师。 public Alumnosdb():base(name或connectionstring:Alumnosdb.ConnectionStringName){}

//静态构造函数
静态校友数据库()
{
//这里我初始化我的数据库
SetInitializer(new AlumnosDbInicializador());
}
公共DbSet校友{get;set;}
公共DbSet Usuarios{get;set;}
公共数据库集

我很绝望,我已经为此挣扎了好几天了,如果有人想看看我的代码,让我知道,我会把它发送给你,但请帮助这些,已经尝试过的Julie Lerman说要删除剩余的程序集,但仍然没有结果,希望这里有人能够帮助我


感谢您未来的建议。

在这里找到了解决方案:

public class UsuariosConfiguracion : EntityTypeConfiguration<tblUsuarios>
     {
    public UsuariosConfiguracion()
    {
        //Relacion uno a uno. Un alumno un Usuarios.
        this.HasRequired(u => u.objAlumno)
            .WithRequiredPrincipal(a => a.objUsuario);
            .Map(p => p.MapKey("AlumnoID")); // <<< Right HERE  
      }
   }
这就解决了过去几天我一直在努力解决的问题,所以如果有人和我有同样的问题,首先检查你的EF关系


感谢阅读此文章。

在这里找到了解决方案:

public class UsuariosConfiguracion : EntityTypeConfiguration<tblUsuarios>
     {
    public UsuariosConfiguracion()
    {
        //Relacion uno a uno. Un alumno un Usuarios.
        this.HasRequired(u => u.objAlumno)
            .WithRequiredPrincipal(a => a.objUsuario);
            .Map(p => p.MapKey("AlumnoID")); // <<< Right HERE  
      }
   }
这就解决了过去几天我一直在努力解决的问题,所以如果有人和我有同样的问题,首先检查你的EF关系

谢谢你阅读这篇文章

this.HasRequired(u => u.objAlumno)
.WithRequiredPrincipal(a => a.objUsuario);