帽儿元素的数目我有两个数据模型博客和后。 BlogId是在后表实体框架4 - 如何从另一个表(通过外键连接)
public class Blog
{
public int ID { get; set; }
public string Title { get; set; }
public virtual ICollection<Post> Posts { get; set; }
...
}
public class Post
{
public int ID { get; set; }
public virtual int BlogId { get; set; }
public string Title { get; set; }
...
}
外键现在这工作得很好,我的仓库是快乐和拉从DB期望的一切。
我的问题是 - 有没有办法限制数量的帖子得到检索。也许一些LINQ魔术?
这里是我目前在库的方法是这样的:
public Business FindBlog(int id)
{
return this.context.Get<Blog>().SingleOrDefault(x => x.ID == id);
}
谢谢拉迪斯拉夫。我正在使用POCO,而且我在这里做了类似于您的建议的事情。但是,如果我可以在一次去DB_的情况下做到这一点,我就会喜欢它。 – zuniga 2011-04-09 22:52:51
@zuniga:我添加了单个查询的版本。 – 2011-04-09 23:12:42
@Ldislav - 工作! – zuniga 2011-04-11 18:55:53