我是 Entity Framework 和 mvc 的新手。
我试图了解 Controller 应该传递给 View 的内容。
它应该是来自 Models (MySolution.Models.Story) 的类还是来自 Entity Framework (MySolution.Story) 的类。
问题是,如果我从 Entity Framework 中选择一个,则 DataTypes 和 html-helpers 无法正常工作。如果我从模型中选择类,则无法从实体类转换为模型类,例如:
TrendEntities TrendDB = new TrendEntities();
public ActionResult Details(int id) {
var Country = TrendDB.Countries.FirstOrDefault(c => c.CountryId ==id);
return View(Country);
}
最佳答案
您正在寻找 AutoMapper或 ValueInjecter .这两个库是“对象到对象”映射器,旨在将值从一个对象映射到另一个对象。我之前只使用过 AutoMapper。它很棒而且很容易拿起。我也听说过有关 ValueInjecter 的好消息。
关于asp.net-mvc - 我应该在 Controller 中使用 Entity Framework 类还是模型类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5379529/