我估计一片帖子写不完这个,慢慢来吧。。。

先上个图,按照图来说明应该容易说清楚一些。

在Model Core核心代码中,老胡创建了一个类 CAMCOCO.Model.Core,要求今后在Model Logic中编写的实体类都必须从这里继承。

Core里提供了两种基类,一个是Entity的基类,一个是Filter基类。

先给出实体类的继承结构:代码有点多,点开再看^v^

 namespace CAMCOCO.Model.Core.Entity
{
using System; #region _BaseEntity 数据实体基类 /// <summary>
/// 数据实体基类
/// </summary>
public abstract class _BaseEntity : IDisposable
{
//do nothing...
public virtual void Dispose()
{
}
} #endregion #region _BasicEnityClone 数据实体克隆类:继承自此的类均可实现Clone自身的操作 /// <summary>
/// 数据实体克隆类:继承自此的类均可实现Clone自身的操作
/// ----------------
/// 本类为抽象类,不能直接实例化
/// </summary>
public abstract partial class _BasicEnityClone : _BaseEntity
{
//在分部类_BasicEnityClone中实现具体定义
} #endregion #region _BaseEntityValidation 数据实体自我验证类:继承自此的类可以进行数据合法性自我验证 /// <summary>
/// 数据实体自我验证类:继承自此的类可以进行数据合法性自我验证
/// </summary>
public abstract partial class _BaseEntityValidation : _BasicEnityClone
{
//在分部类_BaseEntityValidation中实现具体定义
} #endregion #region BaseEntityNormal 标准数据实体类:构成一个数据实体的基本属性 /// <summary>
/// 标准数据实体类:构成一个数据实体的基本属性
/// </summary>
public abstract partial class BaseEntityNormal : _BaseEntityValidation
{
//在分部类BaseEntityNormal中实现具体定义
} #endregion #region BaseEntityOrder 可自定义排序的数据实体类:通过增加OrderIndex属性实现自定义排序 /// <summary>
/// 可自定义排序的数据实体类:通过增加OrderIndex属性实现自定义排序
/// </summary>
public abstract partial class BaseEntityOrder : BaseEntityNormal
{
//在分部类BaseEntityOrder中实现具体定义
} #endregion #region BaseEntityTree 支持树形结构的数据实体类:通过增加ParentId属性实现树形结构 /// <summary>
/// 支持树形结构的数据实体类:通过增加ParentId属性实现树形结构
/// </summary>
public abstract partial class BaseEntityTree : BaseEntityOrder
{
//在分部类BaseEntityTree中实现具体定义
} #endregion }

简单说来就是 _BaseEntity -> _BasicEnityClone -> _BaseEntityValidation -> BaseEntityNormal -> BaseEntityOrder -> BaseEntityTree

_BasicEnityClone 虚类实现了实体间属性克隆的功能,这个在老胡的架构里很重要,在后面聚合方法的add和update里会说到为什么这么做。

_BaseEntityValidation 虚类则实现了实体模型的自我验证功能,一个实体对象数据是否合法(比如必填字段是否填写、数据库中是否存在同名记录等等),都是通过这个虚类中的代码来实现的。(下一节来说明这个东东了)

Entity基类就是所有实体的基类了,在以前的项目实践中,老胡总结出三种常见的数据(实体)模型来:

1、BaseEntityNormal模型:标准的数据模型,每条数据(每个实体)都具备一个唯一编号,也就是ID。在这之上,老胡又增加了几条标准,比如删除标记,比如记录时间。

 namespace CAMCOCO.Model.Core.Entity
{
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; public partial class BaseEntityNormal
{
/// <summary>
/// 实体索引,在数据库中是一个自增标识,并且定义为主键,具备唯一性和聚集索引特性
/// </summary>
[Key]
public long Id { get; set; } public class EntityNormalPropertyClass
{ /// <summary>
/// 实体创建时间,此时间作为数据创建的备案记录,在任何条件下均不允许修改
/// </summary>
[Required]
[Index(IsClustered = false, IsUnique = false)]
public DateTime GenerateTime { get; set; } ///// <summary>
///// 实体数据发布人索引,当无法明确数据来源时,这个属性可以设置为0 【老胡说事:这个东西已经被老胡无情地砍掉了,真没啥用!!】
///// </summary>
//[Index(IsClustered = false, IsUnique = false)]
//public long OwnershipId { get; set; } /// <summary>
/// 数据删除标志位,当为true时表示这是一条已删除数据
/// </summary>
[Index(IsClustered = false, IsUnique = false)]
public bool DeleteFlag { get; set; } /// <summary>
/// 实体数据删除时间
/// </summary>
[Index(IsClustered = false, IsUnique = false)]
public DateTime DeleteTime { get; set; }
} public EntityNormalPropertyClass System { get; set; }
}
}

2、BaseEntityOrder模型。在常见的系统设计中,有一类数据并非是根据ID来顺序或反序排列的,它们需要使用自定义排序,比如一个字典项。这类模型除了标准的实体属性外,应该还有一个自定义排序的Order_Index字段。

 namespace CAMCOCO.Model.Core.Entity
{
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; public partial class BaseEntityOrder
{
public class EntityOrderPropertyClass
{
/// <summary>
/// 自定义排序时,数据的排序序号,可根据此来进行ASC或DESC的排序
/// </summary>
[Index(IsClustered = false, IsUnique = false)]
public int Index { get; set; }
}
public EntityOrderPropertyClass Order { get; set; }
}
}

3、BaseEntityTree模型。还有一种模式的数据格式也是很常见的,就是树形模型。例如我们在做组织架构时、商品类目时,就肯定会用到这种模型了。老胡也把这种模型给定义出来了,增加了个ParentId的属性。

 namespace CAMCOCO.Model.Core.Entity
{
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; public partial class BaseEntityTree
{
public class EntityTreePropertyClass
{
/// <summary>
/// 实体数据的父节点索引,在Tree模型或父子关系模型中,用于表现层级结构的属性
/// </summary>
[Index(IsClustered = false, IsUnique = false)]
public long ParentId { get; set; }
} public EntityTreePropertyClass Tree { get; set; }
}
}

额,有了这三种基本模型,绝大部分格式的数据结构咱都能满足了,当然出了更特殊的数据结构的时候,如果有必要,我们再来增加一种就好了。

为什么要把这三种模型作为标准提出来呢?因为老胡的架构想实现一个功能,那就是,只要你是BaseEntityOrder派生出来的,那老胡的架构自身就能提供标准的移动接口来管理数据的上移、下移、置顶、置尾功能了,不用你再去写代码(到处写实现相同功能的代码一直是老胡深恶痛绝的)。

至于怎么实现这个东东?在后面的Business Core里会说到的。

再说说BaseFilter基类吧,因为在UI层会用到两个很重要的东西,一个是实体类的定义,比如在界面上显示一个客户资料时,我们一般这样做:

Customer cus = iCustomerQuery.findCustomer(customerId);

cus.Name...

cus.Address...

我们在使用Customer时,必须有这个实体类的原型定义,SO,实体模型必须暴露给UI层使用。

为什么业务层又可以不暴露给UI层呢,因为老胡在中间加了个SOA层,业务层是暴露给SOA的,UI对业务的操作是通过SOA来进行的,所以不强制要求UI知道业务层。

当UI需要查找某些数据时,老胡希望有一个尽量规范的格式来进行查询交互,所以引入了Filter这个概念。UI将需要的查询条件构造为一个符合要求的Filter,然后交给SOA,由SOA转发给Business,业务层就清楚需要查询什么样的数据了。

so,,,,Filter是什么?Filter就是在老胡架构中用于描述筛选条件的一个特殊类,目的是用来减少函数调用(如findXXXXList())中的参数个数的!

 namespace CAMCOCO.Model.Core.Filter
{
using CAMCOCO.Common.CommonTypeDefine.CommunicationProtocol; public abstract class BaseFilter
{
public DataPaging PageInfo { get; set; }
public string[] OrderName { get; set; }
public bool[] IsAsc { get; set; } /// <summary>
/// 支持IdList模式
/// </summary>
public string Id { get; set; }
public bool DeleteFlag { get; set; }
/// <summary>
/// 具体时间
/// </summary>
public string GenerateTime { get; set; }
/// <summary>
/// 时间段-开始
/// </summary>
public string GenerateTime_start { get; set; }
/// <summary>
/// 时间段-结束
/// </summary>
public string GenerateTime_end { get; set; }
public string DeleteTime { get; set; }
public string DeleteTime_start { get; set; }
public string DeleteTime_end { get; set; } public string MutiSearchKeywords { get; set; } public BaseFilter()
{
PageInfo = new DataPaging() { PageIndex = , PageSize = , TotalCount = , PageCount = , };
OrderName = new string[] { "Id" };
IsAsc = new bool[] { false }; Id = "";
DeleteFlag = false;
GenerateTime = "";
GenerateTime_start = "";
GenerateTime_end = "";
DeleteTime = "";
DeleteTime_start = "";
DeleteTime_end = ""; MutiSearchKeywords = "";
}
}
}

可以看到,在老胡的架构中,凡是有查询数据的时候都可以通过Filter构造一些标准的查询条件,这里包括页面尺寸信息(每页多少条数据、第几页、数据库中一共多少条符合条件的数据、有多少页),删除标记,数据生成时间(范围),数据删除时间(范围),甚至可以进行关键字模糊查询(MutiSearchKeywords)。

每个具体的实体模型自身还具备什么特殊的查询条件?OK,从BaseFilter派生出去,做一个新的EntityFilter就搞定了。

GO ON....待续

[CAMCOCO][C#]我的系统架构.服务器端.(三)----Model层的更多相关文章

  1. [CAMCOCO][C#]我的系统架构.服务器端.(二)----DATA层

    这一层在园子里有很多很多的介绍了,这层写好之后老胡也没多研究,基本上就是参考的园子里大咖们的写法,具体的说明老胡也细说不了了,把接口和思路简单描述一下就好,如果有问题还是那句话,感谢您不吝赐教,老胡这 ...

  2. [CAMCOCO][C#]我的系统架构.服务器端.(四)----Model层 实体的自我验证

    这是Model的第二篇,上一篇点这里 这块完全是扒了@何镇汐大神博客里的教程实现的,在这之前完全没想到数据验证居然可以这样做!!在此表示严重感谢!!! 点击这里可以去了解这个方法的原理,老胡估计自己是 ...

  3. [CAMCOCO][C#]我的系统架构.服务器端.(一)

    尽量少的前言 虽然写了N年代码了,但总觉得什么东西都是囫囵吞枣,无法尽得其精髓.最近整理了一套心目中的架构,如有错误之处,烦劳不吝指正,老胡在此不胜感激!! 第一篇 我心目中的架构 做了无数个系统,写 ...

  4. [CAMCOCO][C#]我的系统架构 总图

    之前写的感觉有点乱,把架构的设计图先放上来吧,对照着说. CAMCOCO架构能够支持的模型: 1.B/S程序,比如CRM什么的,和访问普通网站没什么区别,都是从WEB服务器上进行操作: 2.APP的服 ...

  5. .net通用权限框架B/S (三)--MODEL层(2)

    接上篇 实体数据模型保存后生成上下文和实体 上下文和实体实际是由根据.tt模版生成的 当实体数据模型.edmx更新保存后,上下文和实体就会根据.tt模版自动更新 生成的上下文继承 DbContext ...

  6. .net通用权限框架B/S (三)--MODEL层(1)

    1.新建c#类库 2.安装配置好entity frame5 3.新建的类库项目上右键"添加--新建项",选择AOD.NET实体数据模型 4.设置数据库连接, 5.选择建好的表 6. ...

  7. Android系统简介(中):系统架构

    Android的系统架构栈分为4层,从上往下分别是Applications.Application framework.Libraries  & Android Runtime.Linux  ...

  8. 认识iOS系统架构

    关于本文: 文章主要介绍iOS系统架构中的四层结构的内容.常用的框架.大致的功能,然后对iOS开发人员的发展提出自己的一些拙见. 一.iOS系统是基于UNIX系统,所有从系统稳定性上来说的确比其他操作 ...

  9. iOS 系统架构

    https://developer.apple.com/library/ios/documentation/Miscellaneous/Conceptual/iPhoneOSTechOverview/ ...

随机推荐

  1. jquery网页字体变大小

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. 【转】Fresco之强大之余的痛楚

    http://www.jianshu.com/p/5364957dcf49 开始之前 如果你有使用的心得,技巧,踩坑经历,希望贡献出来,我会在TODO中慢慢添加(^^)/ 关于Fresco Fresc ...

  3. Bit Twiddling Hacks

    http://graphics.stanford.edu/~seander/bithacks.html Bit Twiddling Hacks By Sean Eron Andersonseander ...

  4. HRESULT 0x80131515 解决方法

    http://254698001.blog.51cto.com/2521548/1339696 很多朋友在加载DLL是发生这样的错误:HRESULT: 0x80131515. 解决方法是,在DLL文件 ...

  5. JSON初探

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式.同时,JSON是 JavaScript 原生格式,这意 ...

  6. 将Excel另存为CSV格式文件

    直接将Excel另存为CSV,速度很快: $CurrentPath = $MyInvocation.MyCommand.Path.substring(0,$MyInvocation.MyCommand ...

  7. OverHust

    https://github.com/fanhongwei/OverHust https://github.com/eltld/OverHust

  8. Ambari源代码分析之总览

    一.基本概念: Resource:Ambari把能够被管理的资源的抽象为一个Resource实例,资源能够包括服务.组件.主机节点等,一个resource实例中包括了一系列该资源的属性: Proper ...

  9. windows下如何github ssh 公钥

    windows下如何github ssh 公钥   1. 安装git,从程序目录打开 "Git Bash"  2. 键入命令:ssh-keygen -t rsa -C " ...

  10. 关于OpenGL+GLSL深度贴图采样

    作者:Nin+.Lee 邮箱:lilei9110@gmail.com * 本文属原创,转载请注明出处. 在GLSL中,存在着sampler2D和sampler2DShadow两种2D贴图采样器.在对一 ...