帽兒元素的數目我有兩個數據模型博客和後。 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