asp.net-mvc - 我应该在 Controller 中使用 Entity Framework 类还是模型类?

标签 asp.net-mvc asp.net-mvc-3 entity-framework

我是 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);  
}  

最佳答案

您正在寻找 AutoMapperValueInjecter .这两个库是“对象到对象”映射器,旨在将值从一个对象映射到另一个对象。我之前只使用过 AutoMapper。它很棒而且很容易拿起。我也听说过有关 ValueInjecter 的好消息。

关于asp.net-mvc - 我应该在 Controller 中使用 Entity Framework 类还是模型类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5379529/

相关文章:

asp.net-mvc - 使用自动映射器映射嵌套对象

angularjs - 无法在 asp.net mvc 中显示来自 s3 存储桶的上传图像

asp.net - 部署 ASP.Net MVC 应用程序最便宜的方法是什么?

用于 URL 生成的 Javascript 变量值未按预期评估

jquery - c# asp.net mvc 中的 json 对象返回未定义

asp.net-mvc-3 - 为什么 Ninject 不解析基类中的 protected 属性?

asp.net-mvc - 域模型: how and where的验证

asp.net-mvc - ASP.NET MVC 中的全局错误处理( Controller 之外)

asp.net-mvc-3 - 当 HTTP 响应状态设置为 400 时 IIS 覆盖 HTTP 响应文本

.net - Linq Select 不会在 EF Core 中检索超过 3 个子级别的对象数据