[英]Entity Framework 7 RC1 relations
Now that I updated to ASP.NET 5 RC1, and Entity Framework 7 RC1, I expected to have relations enabled in my models. 现在,我已更新到ASP.NET 5 RC1和Entity Framework 7 RC1,我希望在模型中启用关系。 But I can't get this to work. 但是我无法使它正常工作。
Here are my models: 这是我的模型:
public class Post
{
public int Id { get; set; }
public string Text { get; set; }
public virtual ICollection<Comment> Comments { get; set; }
}
public class Comment
{
public int Id { get; set; }
public string Text { get; set; }
public int PostId { get; set; }
public virtual Post Post { get; set; }
}
I have inserted manually some data in the tables and tried to access Comments
property of a post like this: 我已经在表中手动插入了一些数据,并尝试访问类似这样的帖子的Comments
属性:
var post = context.Posts.Where(x => x.Id == 1).FirstOrDefault();
var sb = new StringBuilder();
foreach(var comment in post.Comments)
{
sb.Append(comment.Text);
}
but the Comments
property is always null. 但是Comments
属性始终为null。 This post has two comments in table. 这篇文章在表中有两个评论。
What I'm doing wrong? 我做错了什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.