【发布时间】:2012-03-18 09:14:58
【问题描述】:
接下来是问题 - 我有 2 个具有一对多关系的实体:
public class Schema
{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid SchemaId { get; set; }
public string Name { get; set; }
public string Content { get; set; }
public string ElementName { get; set; }
public List<Element> Elements { get; set; }
}
public class Element
{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid ElementId { get; set; }
public Guid SchemaId { get; set; }
public string Content { get; set; }
public Schema InSchema { get; set; }
}
并且项目引用了 EntityFramework v4.3 包。 在数据库中存储一些具有相关元素的模式后,我加载模式列表(例如,var schemasList=context.Schemas.ToList())。在此之后,在 Elements 属性值的所有 Schema 实例中为空。现在我通过为实体添加动态代理来解决这个问题,但这在许多开发场景中都有一些不好的影响(例如,保存可能会导致“通过多个上下文跟踪实体”错误)。 感谢您对此问题的任何帮助。
【问题讨论】:
标签: c# entity-framework-4.1 code-first entity-framework-4.3