【发布时间】:2012-04-12 15:48:48
【问题描述】:
我是 NopCommerce v2.4 的新手,想知道在哪里编写代码(通过在 admin 或 nop.web 部分创建新模型)
【问题讨论】:
标签: entity-framework-4 nopcommerce
我是 NopCommerce v2.4 的新手,想知道在哪里编写代码(通过在 admin 或 nop.web 部分创建新模型)
【问题讨论】:
标签: entity-framework-4 nopcommerce
我花了很多时间来深入研究这个问题的深度。我可以将解决方案总结如下:
创建实体类(例如 Entity.cs)
路径:Nop/Core/Domain/Entity.cs
创建映射类(例如 EntityMap.cs)
路径:Nop/Data/Mapping/EntityMap.cs
为 MVC 创建模型(例如 EntityModel.cs)
路径:Nop/Admin/Models/EntityModel.cs 或 Nop/Web/Models/EntityModel.cs
为模型创建一个验证器(例如 EntityValidator.cs)
路径:Nop/Admin/Validators/EntityValidator.cs 或 Nop/Web/Validators/EntityValidator.cs
在 AutoMapperStartupTask.cs 上为实体和模型创建映射配置
路径:Nop/Admin/Infrastructure 或 Nop/Web/Infrastructure
在 MappingExtensions.cs 上应用模型和实体之间的映射
路径:Nop/Admin 或 Nop/Web
创建服务类和服务接口(例如 EntityService.cs 、 IEntityService.cs)
路径:Nop/Services/EntityService.cs 和 Nop/Services/IEntityService.cs
为依赖注入注册服务
路径:Nop/Web/Framework/DependencyRegistrar.cs
最后为给定模型创建控制器和视图
由于 Nop Commerce 使用 MVC3 的第一个版本,因此不支持数据库迁移,您必须手动更改数据库表。因为 MVC 代码优先必须删除并重新创建数据库以反映对数据库的更改。
如果您想了解任何步骤的更多细节,请告诉我 - 我可以详细描述每个步骤。 希望这会有所帮助。
【讨论】:
Behnam Esmaili 解决方案是正确的,但他们忘记在 Presentation 中添加一个注册新创建的控制器服务的步骤 ==> Nop.Web.Framework ==> DependencyRegistrar.cs 像这样
builder.RegisterType<EntityService>().As<IEntityService>().InstancePerHttpRequest();
【讨论】:
此问题已在 NOPCommerce 论坛here回复
http://www.nopcommerce.com/docs/75/plugin-with-data-access.aspx
【讨论】:
@Behnam Esmaili
回答了完美的答案,但是您应该在创建控制器时遇到问题,因为您无法从 IEntityService 创建实例,因为 nopCommerce 使用依赖注入,并且这是由 AutoFac 容器控制的。
所以你持有Check this post on nopCommerce forum,这将有助于你完成工作。
还有一个注意事项, 如果您想避免手动更改数据库,您应该在新版本的 nopCommerce 上执行从 1 到 8 的步骤并安装它,数据库将使用您对模型所做的更改来创建。
【讨论】:
【讨论】: