介绍
- 我是实体框架的新手
- 我正在使用代码优先
用例
我必须遵循表格
[Table("TBL_UserVariant")]
public class UserVariant
{
[Key, Column(Order = 0)]
public int UserId { get; set; }
[Key, Column(Order = 1)]
public int VarId { get; set; }
public string Value { get; set; }
}
[Table("TBL_UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string eMail { get; set; }
}
我希望 TBL_UserProfile 引用所有 TBL_UserVariant 条目的列表,其中 TBL_UserProfile::UserId == TBL_UserVariant::UserId
以下是我的目标示例
[Table("TBL_UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string eMail { get; set; }
public UserVariant[] variants;
}
其中 'UserProfile::variants' 应包含 'TBL_UserProfile::UserId == TBL_UserVariant::UserId' 的项目列表
问题
这可以直接使用 EF 吗?或者,我应该实现一个填充 'UserProfile::variants' ~manually~ 的包装器吗?