【发布时间】:2011-08-29 21:09:37
【问题描述】:
我一直在尝试在 EF 4.1 中创建模型来表示具有单个表和包含来自其他两个表的外键的列的数据库模式,但是在注释和流畅的 API 方面都没有运气。此处显示了一个示例模型:
public class User
{
...
public virtual ExtendedAttribute ExtendedAttributes { get; set; }
}
public class Account
{
...
public virtual ExtendedAttribute ExtendedAttributes { get; set; }
}
public class ExtendedAttribute
{
public Guid Id {get; set;}
public Guid ItemId {get; set;} // both Account.Id and User.Id stored here
public string Value { get; set; }
}
目前这些实体的配置对于用户和帐户模型构建器来说都是这样的:
this.HasOptional(u => u.ExtendedAttributes).WithRequired();
关于如何实现的任何想法?非常感谢。
【问题讨论】:
标签: entity-framework-4 ef-code-first