Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.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# 实体框架导航属性不为';t加载正确的实体_C#_Asp.net_Entity Framework_Ef Code First - Fatal编程技术网

C# 实体框架导航属性不为';t加载正确的实体

C# 实体框架导航属性不为';t加载正确的实体,c#,asp.net,entity-framework,ef-code-first,C#,Asp.net,Entity Framework,Ef Code First,我有这些课程 public class Address { [Key] [Required] [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)] public int ID { get; set; } } public class Info { [Key] [Required] [Databas

我有这些课程

public class Address
{
    [Key]
    [Required]
    [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
    public int ID { get; set; }
}

public class Info
{
    [Key]
    [Required]
    [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
    public int ID { get; set; }

    public int AddressID { get; set; }

    public virtual Adress Adress { get; set; }
}

public class Prop
{
    [Key]
    [Required]
    [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
    public int ID { get; set; }
    public int InfoID { get; set; }
    public virtual Info Info { get; set; }
}
假设我有5个道具、5个信息和1000个地址实体。当我像这样航行时

ObjectContext obj = new ObjectContext();
Prop pl = obj.Props.ToList();
foreach(Prop p in pl)
{
   Response.Write(p.Info.Address.ID);
   Response.Write(p.Info.AddressID);
}
第一个响应。写下ID 1到5。这是表中的前5行。但这是不正确的

因为,第二个反应,写下真实的反应。通过我在Info表中添加的外键实际引用地址表ID列的。他们就像568,12596,22

导航属性似乎正在加载地址表中的第一行

我做了一些研究,发现这可能是由于EF中的延迟加载函数造成的。但我想不出一条出路。有人能帮我吗