Plugin with data access
In this tutorial I'll be using the nopCommerce plugin architecture to implement a product view tracker.
We will start coding with the data access layer, move on to the service layer, and finally end on dependency injection.
Getting started
Create a new class library project "Nop.Plugin.Other.ProductViewTracker"
Add the following folders and decription.txt file.
Description.txt
Group: Other
FriendlyName: ProductViewTracker
SystemName: Other.ProtudctViewTracker
Version: 1.00
SupportedVersions: 3.20
Author: nopCommerce team
DisplayOrder: 1
FileName: Nop.Plugin.Other.ProductViewTracker.dll
Also add the following references and set their "Copy Local" property to "False":
- Nop.Core.dll
- Nop.Data.dll
- Nop.Services.dll
- Nop.Web.Framework.dll
- EntityFramework.dll
- System.Data.Entity.dll
- System.Web.dll
- System.Web.Mvc.dll
- Autofac.dll
- Autofac.Configuration.dll
- Autofac.Integration.Mvc.dll
The Data Access Layer
Inside of the "domain" namespace we're going to create a public class named TrackingRecord. This class extends BaseEntity, but it is otherwise a very boring file. Something to remember is that all properties are marked as virtual and it isn't just for fun. Virtual properties are required on database entities because of how Entity Framework instantiates and tracks classes. One other thing to note is that we do not have navigation properties (relational properties), and I'll cover those in more detail later.
namespace Nop.Plugin.Other.ProductViewTracker.Domain
{
public class TrackingRecord : BaseEntity
{
public virtual int ProductId { get; set; }
public virtual string ProductName { get; set; }
public virtual int CustomerId { get; set; }
public virtual string IpAddress { get; set; }
public virtual bool IsRegistered { get; set; }
}
}
The next class to create is the Entity Framework mapping class. Inside of the mapping class we map the columns, table relationships, and the database table.
namespace Nop.Plugin.Other.ProductViewTracker.Data
{
public class TrackingRecordMap : EntityTypeConfiguration<TrackingRecord>
{
public TrackingRecordMap()
{
ToTable("ProductViewTracking"); //Map the primary key
HasKey(m => m.Id);
//Map the additional properties
Property(m => m.ProductId);
//Avoiding truncation/failure
//so we set the same max length used in the product tame
Property(m => m.ProductName).HasMaxLength();
Property(m => m.IpAddress);
Property(m => m.CustomerId);
Property(m => m.IsRegistered);
}
}
}
Plugin with data access的更多相关文章
- FunDA(0)- Functional Data Access accessible to all
大数据.多核CPU驱动了函数式编程模式的兴起.因为函数式编程更适合多线程.复杂.安全的大型软件编程.但是,对许多有应用软件开发经验的编程者来说,函数式编程模式是一种全新的.甚至抽象的概念,可能需要很长 ...
- Enterprise Library - Data Access Application Block 6.0.1304
Enterprise Library - Data Access Application Block 6.0.1304 企业库,数据访问应用程序块 6.0.1304 企业库的数据访问应用程序块的任务简 ...
- Top 10 steps to optimize data access in SQL Server
2009年04月28日 Top 10 steps to optimize data access in SQL Server: Part I (use indexing) 2009年06月01日 To ...
- [翻译]比较ADO.NET中的不同数据访问技术(Performance Comparison:Data Access Techniques)
Performance Comparison: Data Access Techniques Priya DhawanMicrosoft Developer Network January 2002 ...
- 问题-Error creating object. Please verify that the Microsoft Data Access Components 2.1(or later) have been properly installed.
问题现象:软件在启动时报如下错误信息:Exception Exception in module zhujiangguanjia.exe at 001da37f. Error creating obj ...
- Apache Cloudstack Development 101 -- Data Access Layer
刚接触CloudStack,也是第一次翻译英文文档,限于水平有限,不当之处欢迎拍砖! 原文地址:https://cwiki.apache.org/confluence/display/CloudSta ...
- 黄聪:Microsoft Enterprise Library 5.0 系列教程(五) Data Access Application Block
原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(五) Data Access Application Block 企业库数据库访问模块通过抽象工厂模式,允许用户 ...
- EnterpriseLibrary 6.0(微软企业库6.0学习笔记) 之Data Access Block 配置和获取链接字符串
EnterpriseLibrary 的特点是快速开发,融合了微软工程师多年的经验,现在在微软内部有专门的一个小组在完善EnterpriseLibray,最近的更新时间是April 2013. 相关链接 ...
- Data access between different DBMS and other txt/csv data source by DB Query Analyzer
1 About DB Query Analyzer DB Query Analyzer is presented by Master Genfeng,Ma from Chinese Mainl ...
随机推荐
- 徐汉彬:亿级Web系统搭建——单机到分布式集群(转载)
文章转载自http://www.csdn.net/article/2014-11-06/2822529/1 当一个Web系统从日访问量10万逐步增长到1000万,甚至超过1亿的过程中,Web系统承受的 ...
- 以Akka为示例,介绍Actor模型
许多开发者在创建和维护多线程应用程序时经历过各种各样的问题,他们希望能在一个更高层次的抽象上进行工作,以避免直接和线程与锁打交道.为了帮助这些开发者,Arun Manivannan编写了一系列的博客帖 ...
- 关于 python 的 @property总结和思考
其实关于@property我到处去搜了很多教程来看,因为公司大量使用了oop的编程而我以前很少写,所以现在来重新补过来. 从使用上来说 加了@property之后最明显的区别就是 class Stud ...
- 解决getOutputStream() has already been called for this response
http://qify.iteye.com/blog/747842 —————————————————————————————————————————————————— getOutputStream ...
- IMAQdx和IMAQ
NI-IMAQdx driver software gives you the ability to acquire images with IEEE 1394 and GigE Vision cam ...
- POJ1837 Balance(DP)
POJ1837http://poj.org/problem?id=1837 题目大意就是说有一个称上有C个挂钩,告诉你每个挂钩的位置,现在有G个重物,求是之平衡的方法数. 转化一下:DP[i][j]表 ...
- 在TFS2013上删除项目
TFSDeleteProject 会永久性损坏团队项目,之后无法恢复该项目. 您应该在使用 TFSDeleteProject 之前备份所有重要的项目数据. 若要使用 TFSDeleteProject ...
- 解决UITableView头部空白
解决方式1: self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.ta ...
- 用vagrant搭建一个自己的lnmp环境(一)
用vagrant搭建自己的lnmp环境 1.工具: a.vagrant b.virtual box c.linux服务器box(此处我使用centos 7.0) 2.安装完vagrant和virtua ...
- Windows 10 Edge浏览器、照片查看程序关闭“平滑滚动”
升级到10后,这两个常用软件的“平滑滚动”功能,个人感觉体验有点不好,特别是图片这个自带程序,看了几十张图后就有点头晕了,所以把它关闭为好: 控制面板\系统和安全\系统\高级系统设置\高级\性能\设置 ...