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 ...
随机推荐
- 基于Heritrix的特定主题的网络爬虫配置与实现
建议在了解了一定网络爬虫的基本原理和Heritrix的架构知识后进行配置和扩展.相关博文:http://www.cnblogs.com/hustfly/p/3441747.html 摘要 随着网络时代 ...
- [WebService]之Schema
schema入门 1:schema出现的目的是通过一个更加合理的方式来编写xml文件的限制(以XML语法的方式) 2:schema可以使用命名空间来支持多个名称相同的元素 3:schema可以很好的的 ...
- Rxjava, RxAndroid, Retrofit 等库的使用
RxJava的基本用法: 关于 unSubscribe() 的调用问题: There is no need to unsubscribe in onCompleted. Take a look at ...
- C++11右值引用
[C++11右值引用] 1.什么是左值?什么是右值? 左值是表达式结束后依然存在的对象:右值是表达式结束时就不再存在的对象. 2.std::move的作用是什么? std::move用于把任意类型转化 ...
- KMP应用http://acm.hdu.edu.cn/showproblem.php?pid=2594
riemann与marjorie拼接后riemannmarjorie前缀与后缀公共部分为 rie 长度为 3(即next[l] = next[14]的值,l为拼接后的长度)但:aaaa与aa拼接后aa ...
- ARM内核全解析
前不久ARM正式宣布推出新款ARMv8架构的Cortex-A50处理器系列产品,以此来扩大ARM在高性能与低功耗 领域的领先地位,进一步抢占移动终端市场份额.Cortex-A50是继Cortex-A1 ...
- Cisco Router WEB管理
目前市场上很多思科路由器或者交换机都可以通过WEB方式配置.尽管很多功能还是只能通过CLI配置,但是一些功能还是很有用的,例如端口的流量监控功能 前期准备: 一.设备的IOS要支持WEB管理功能 ...
- TcxDBVerticalGrid优秀的编辑控件
- CSS单词换行and断词
背景 某天老板在群里反馈,英文单词为什么被截断了? 很显然,这是我们前端的锅,自行背锅.这个问题太简单了,css里加两行属性,分分钟搞定. 1 2 word–break: keep–all; wo ...
- POJ1948Triangular Pastures(DP)
POJ1948http://poj.org/problem?id=1948 题目大意就是说给你n个木棍让你用它们摆成一个三角形 使得这个三角形的面积最大. 这个题我之前想的时候一直纠结怎么通过之前的 ...