【发布时间】:2014-08-09 17:12:15
【问题描述】:
假设我有两个班级,
public class UserBio {
[Key]
public string Id { get; set; }
[Required]
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Required]
[Display(Name = "Last Name")]
public string LastName { get; set; }
}
public class UserPosts
{
[Key]
public int PostId { get; set; }
public string CreatedBy { get; set; }
public string Description { get; set; }
}
我的问题是,如何将 UserPosts 中的 CreatedBy 映射到 UserBio 中的 Id 属性?我知道一种方法是用 UserBio 替换 CreatedBy 的数据类型。但由于某些问题,这似乎不是一个好主意。我想将 CreatedBy 作为字符串插入,在检索期间,UserPosts 还包含用户的 UserBio。 你能帮我解决这个问题吗?我必须为此使用 Fluent api 吗?或者我可以通过数据注释来实现吗?
【问题讨论】:
-
下面的回答是否帮助或回答了您的问题?
标签: c# asp.net asp.net-mvc entity-framework entity-framework-6