【发布时间】:2012-10-23 23:05:56
【问题描述】:
这是采用代码优先方法的最新实体框架。 一位客户可以拥有多个属性:
public class Customer
{
[Key]
public int Id { get; set; }
public virtual List<CustomerToPropertyMapping> PropertyIds { get; set; }
}
[Table("CustomerToProperty")]
public class CustomerToPropertyMapping
{
[Key, Column(Order = 1)]
public int PropertyId { get; set; }
}
当我加载数据时,一切正常。当我试图拯救客户时,我得到了
保存不公开外键的实体时出错 他们关系的属性。 EntityEntries 属性将 返回 null,因为无法将单个实体标识为源 的例外。可以进行保存时的异常处理 通过在实体类型中公开外键属性更容易。看 InnerException 了解详情。
即使我有同样的事情
[Key, Column(Order = 0)]
CustomerId
在 CustomerToPropertyMapping 类中。
检索映射而不是映射到的对象的正确方法是什么?
【问题讨论】:
标签: c# entity-framework mapping