【发布时间】:2015-12-25 21:42:25
【问题描述】:
如果我有以下两个models:
public class Book
{
public int ID { get; set; }
public string Title { get; set; }
//other properties
public virtual Category Category { get; set; }
}
public class Category
{
public int ID { get; set; }
public string CategoryName { get; set; }
public virtual ICollection<Book> Books { get; set; }
}
我正在向视图发送List<Book>:
public class ShopController : Controller
{
private BookStoreMDFEntities db = new BookStoreMDFEntities();
public ActionResult Index()
{
var list = db.Books.Include("Category").ToList();
return View(list);
}
}
如何查看Book 列表中每个类别的类别名称和出现次数?
示例输出:
- 科学:2
- 数学:4 ...
【问题讨论】:
标签: c# asp.net-mvc entity-framework linq razor