我有一个简单的课程:
public class Member
{
public int AccountId { get; set; }
public string Name { get; set; }
public string Role { get; set; }
public DateTime MemberSince { get; set; }
}
我需要将AccountId作为密钥,但如果我使用“密钥”属性,则将其转换为对我不起作用的标识(此数据来自其他来源,因此无法更改该值)。
还有其他办法吗?
除了答案使用了我不能做的流畅界面之外,还有almost the exact same question here。
答案 0 :(得分:1)
当然,您可以使用:
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public int AccoungId { get; set; }