C# EF6应用程序未序列化集合
我正在处理我的第一个实体框架/MVC应用程序,并且在应用程序的API方面遇到了一个问题。这是密码C# EF6应用程序未序列化集合,c#,asp.net-mvc,entity-framework,asp.net-mvc-4,serialization,C#,Asp.net Mvc,Entity Framework,Asp.net Mvc 4,Serialization,我正在处理我的第一个实体框架/MVC应用程序,并且在应用程序的API方面遇到了一个问题。这是密码 [DataContract(IsReference=true)] [KnownType(typeof(Project.Models.StepByStep))] public class StepByStep { [DataMember] public int Id { get; set; } [Required] [DataMember] public str
[DataContract(IsReference=true)]
[KnownType(typeof(Project.Models.StepByStep))]
public class StepByStep
{
[DataMember]
public int Id { get; set; }
[Required]
[DataMember]
public string Name { get; set; }
[Required]
[DataMember]
public int Version { get; set; }
[DataMember]
public virtual ICollection<Step> Steps { get; set; }
[DataMember]
public virtual ICollection<StepPath> PathTable { get; set; }
}
使用用于MVC的脚手架控制器,我创建了一个StepByStep,并创建了附加到StepByStep的3个步骤。这在MVC控制器中得到了准确的反映
当使用API并调用StepByStep实体时,我希望看到来自这些步骤的大量信息,但我什么也看不到,它们是空的
<StepByStep xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" xmlns="http://schemas.datacontract.org/2004/07/Models" z:Id="i1">
<Id>1</Id>
<Name>TestApp</Name>
<PathTable i:nil="true"/>
<Steps i:nil="true"/>
<Version>1</Version>
</StepByStep>
1.
特斯塔普
1.
有人能告诉我为什么我的项目的API部分无法访问/序列化父实体中的步骤和路径集合吗?在检索父实体时,请确保在API调用中包含子对象。在某些情况下,使用EF时不会自动包含子对象。请参阅本手册的“快速加载”部分
注意:这在上面的文章中提到过,但我在这里要提到:也有使用延迟加载的选项(所有内容都包含在其中),但这对于序列化来说可能是一个非常糟糕的主意,因为您最终可能会拉回比您想要的更多的数据。嘿,谢谢!这篇文章确实明确了急切加载和懒惰加载之间的区别。让它工作起来。
<StepByStep xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" xmlns="http://schemas.datacontract.org/2004/07/Models" z:Id="i1">
<Id>1</Id>
<Name>TestApp</Name>
<PathTable i:nil="true"/>
<Steps i:nil="true"/>
<Version>1</Version>
</StepByStep>