EF4.4 - 无法识别列表导航属性

时间:2013-01-15 05:13:23

标签: entity-framework-4 navigation

我正在学习EF,我遇到了导航方面的问题。我希望你们能告诉我路径:)

当我运行此代码时,EF会显示以下消息:

  

System.Reflection.TargetInvocationException:调用目标抛出了异常。 ---> System.MissingMethodException:找不到方法:'System.Collections.Generic.List`1 Sis.Model.Ft1Cap300.get_Ft1Cap300l()'。“

我真的不知道问题所在;我认为我的导航属性没问题,但EF表示它无法识别Ft1Cap300.Ft1Cap300l属性。

我有3个模型实体。我将发布clases及其配置

public class Ft1Caratula
{
    [Key]
    public String EncuestaId { get; set; }
    public Int32 DistritoId { get; set; }       //fk
    public String Conglomerado { get; set; }
    [Required]
    public Int32 Area { get; set; }
    [Required]
    public Int32 NumHogar { get; set; }
    [Required]
    public Int32 TotHogar { get; set; }
    public Int32 TipoComunidad { get; set; }
    [Required]
    public String JefeNombres { get; set; }
    [Required]
    public String JefeApePat { get; set; }
    [Required]
    public String JefeApeMat { get; set; }
    public Int32 DirTipo { get; set; }
    public String DirDireccion { get; set; }
    public Nullable<Int32> Dir1 { get; set; }
    public String Obs { get; set; }
    public Int32 Idioma { get; set; }
    public String Idioma_o { get; set; }
    [Required]
    public DateTime Ent1Fecha { get; set; }
    [Required]
    public Int32 Ent1Res { get; set; }
    public String Ent1Res_o { get; set; }
    public String EncId { get; set; }           
    public DateTime EncFecha { get; set; }

    public virtual UbiDistrito Distrito { get; set; }
    public virtual SegTecnico Encuestador { get; set; }

    public virtual List<Ft1Cap100> Ft1Cap100 { get; set; }
    public virtual List<Ft1Cap300> Ft1Cap300 { get; set; }
}

public class Ft1Cap300
{
    public String EncuestaId { get; set; }
    [Required]
    public int P301 { get; set; }

    public virtual Ft1Caratula Ft1Caratula { get; set; }
    public virtual List<Ft1Cap300l> Ft1Cap300l { get; set; }
}

public class Ft1Cap300l
{
    public String EncuestaId { get; set; }
    public int NOrden { get; set; }
    public String P302 { get; set; }
    [Required]
    public int P303 { get; set; }
    [Required]
    public int P304 { get; set; }
    public String P305_1 { get; set; }
    public String P305_2 { get; set; }
    public String P305_3 { get; set; }

    public virtual Ft1Cap300 Ft1Cap300 { get; set; }
}

public class Ft1CaratulaConfiguracion : EntityTypeConfiguration<Ft1Caratula>
{
    public Ft1CaratulaConfiguracion()
    {
        ToTable("ft1caratula", "data");
        HasRequired(p => p.Encuestador).WithMany(l => l.Ft1Caratulas).HasForeignKey(p => p.EncId);
        HasRequired(p => p.Distrito).WithMany(l => l.Ft1Caratulas).HasForeignKey(p => p.DistritoId);
    }
}

public class Ft1Cap300Configuracion : EntityTypeConfiguration<Ft1Cap300>
{
    public Ft1Cap300Configuracion()
    {
        ToTable("ft1cap300", "data");
        HasKey(p => new { p.EncuestaId });
        HasRequired(p => p.Ft1Caratula).WithMany(l => l.Ft1Cap300).HasForeignKey(p => p.EncuestaId);

    }
}

public class Ft1Cap300lConfiguracion : EntityTypeConfiguration<Ft1Cap300l>
{
    public Ft1Cap300lConfiguracion()
    {
        ToTable("ft1cap300l", "data");
        HasKey(p => new { p.EncuestaId, p.NOrden });
        HasRequired(p => p.Ft1Cap300).WithMany(l => l.Ft1Cap300l).HasForeignKey(p => p.EncuestaId);
    }
}

我希望你能帮助我。我有一本书“编程EF:CodeFirst”作为指南。

1 个答案:

答案 0 :(得分:0)

您的代码目前存在以下问题 在

public class Ft1CaratulaConfiguracion : EntityTypeConfiguration<Ft1Caratula>
    {
        public Ft1CaratulaConfiguracion()
        {
            ToTable("ft1caratula", "data");
            HasRequired(p => p.Encuestador).WithMany(l => l.Ft1Caratulas).HasForeignKey(p => p.EncId);
            HasRequired(p => p.Distrito).WithMany(l => l.Ft1Caratulas).HasForeignKey(p => p.DistritoId);
        }
    }

类Ft1Caratula没有属性EncuestadorDistrito

一般在

public virtual List<Ft1Cap100> Ft1Cap100 { get; set; }

您正在使用属性作为类型。所以你应该得到一些编译时错误。