引言(NParsing框架功能简介、NParsing的由来)
NParsing框架功能简介
1、无需编写数据持久层代码。
2、无需编写SQL语句。
3、支持一个项目连接多数据库。
4、支持(Access、MySQL、SQL Server、Oracle)多数据库平台。
5、支持多字段排序。
6、支持事务提交。
7、一切以对象模型为主。
控制器组件接口代码
代码
1 using System.Collections.Generic;
2
3 namespace DotNet.Frameworks.NParsing.Interface
4 {
5 public interface IObHelper<M>
6 {
7 /// <summary>
8 /// 检查是否存在
9 /// </summary>
10 /// <param name="iObParameter"></param>
11 /// <returns></returns>
12 bool Exists(IObParameter iObParameter);
13 bool Exists(IObTransaction iObTransaction, IObParameter iObParameter);
14
15 /// <summary>
16 /// 添加一个对象到数据库
17 /// </summary>
18 /// <param name="model"></param>
19 /// <returns></returns>
20 bool Add(M model);
21 bool Add(IObTransaction iObTransaction, M model);
22
23 /// <summary>
24 /// 从数据库删除一个对象
25 /// </summary>
26 /// <param name="iObParameter"></param>
27 /// <returns></returns>
28 bool Delete(IObParameter iObParameter);
29 bool Delete(IObTransaction iObTransaction, IObParameter iObParameter);
30
31 /// <summary>
32 /// 更新一个数据库对象
33 /// </summary>
34 /// <param name="model"></param>
35 /// <param name="iObParameter"></param>
36 /// <returns></returns>
37 bool Update(M model, IObParameter iObParameter);
38 bool Update(IObTransaction iObTransaction, M model, IObParameter iObParameter);
39
40 /// <summary>
41 /// 获取一个数据库对象
42 /// </summary>
43 /// <param name="iObParameter"></param>
44 /// <returns></returns>
45 M GetModel(IObParameter iObParameter);
46 M GetModel(IObTransaction iObTransaction, IObParameter iObParameter);
47
48 ///// <summary>
49 ///// 获取一个数据库对象的Json字符串
50 ///// </summary>
51 ///// <param name="iObParameter"></param>
52 ///// <returns></returns>
53 //string GetJsonModel(IObParameter iObParameter);
54 //string GetJsonModel(IObTransaction iObTransaction, IObParameter iObParameter);
55
56 /// <summary>
57 /// 获取一个数据库对象集合
58 /// </summary>
59 /// <returns></returns>
60 IList<M> GetList();
61 IList<M> GetList(IObParameter iObParameter);
62 IList<M> GetList(IObSort iObSort);
63 IList<M> GetList(IObParameter iObParameter, IObSort iObSort);
64 IList<M> GetList(IObTransaction iObTransaction);
65 IList<M> GetList(IObTransaction iObTransaction, IObParameter iObParameter);
66 IList<M> GetList(IObTransaction iObTransaction, IObSort iObSort);
67 IList<M> GetList(IObTransaction iObTransaction, IObParameter iObParameter, IObSort iObSort);
68
69 ///// <summary>
70 ///// 获取一个数据库对象集合的Json字符串
71 ///// </summary>
72 ///// <returns></returns>
73 //string GetJsonList();
74 //string GetJsonList(IObParameter iObParameter);
75 //string GetJsonList(string sortName, int sort);
76 //string GetJsonList(string sortName, int sort, IObParameter iObParameter);
77 //string GetJsonList(IObTransaction iObTransaction);
78 //string GetJsonList(IObTransaction iObTransaction, IObParameter iObParameter);
79 //string GetJsonList(IObTransaction iObTransaction, string sortName, int sort);
80 //string GetJsonList(IObTransaction iObTransaction, string sortName, int sort, IObParameter iObParameter);
81
82 /// <summary>
83 /// 获取一个数据库对象分页集合
84 /// </summary>
85 /// <param name="pageSize"></param>
86 /// <param name="pageIndex"></param>
87 /// <param name="iObSort"></param>
88 /// <param name="count"></param>
89 /// <returns></returns>
90 IList<M> GetList(int pageSize, int pageIndex, IObSort iObSort, out int count);
91 IList<M> GetList(int pageSize, int pageIndex, IObParameter iObParameter, IObSort iObSort, out int count);
92
93 ///// <summary>
94 ///// 获取一个数据库对象分页集合的Json字符串
95 ///// </summary>
96 ///// <param name="pageSize"></param>
97 ///// <param name="pageIndex"></param>
98 ///// <param name="sortName"></param>
99 ///// <param name="sort"></param>
100 ///// <param name="count"></param>
101 ///// <returns></returns>
102 //string GetJsonList(int pageSize, int pageIndex, string sortName, int sort, out int count);
103 //string GetJsonList(int pageSize, int pageIndex, string sortName, int sort, IObParameter iObParameter, out int count);
104
105 /// <summary>
106 /// 获取记录数
107 /// </summary>
108 /// <returns></returns>
109 int GetCount();
110 int GetCount(IObParameter iObParameter);
111 int GetCount(IObTransaction iObTransaction);
112 int GetCount(IObTransaction iObTransaction, IObParameter iObParameter);
113
114 /// <summary>
115 /// 获取某列最大值
116 /// </summary>
117 /// <param name="propertyName"></param>
118 /// <returns></returns>
119 object GetMaxScalar(string propertyName);
120 object GetMaxScalar(string propertyName, IObParameter iObParameter);
121 object GetMaxScalar(IObTransaction iObTransaction, string propertyName);
122 object GetMaxScalar(IObTransaction iObTransaction, string propertyName, IObParameter iObParameter);
123
124 /// <summary>
125 /// 获取某列最小值
126 /// </summary>
127 /// <param name="propertyName"></param>
128 /// <returns></returns>
129 object GetMinScalar(string propertyName);
130 object GetMinScalar(string propertyName, IObParameter iObParameter);
131 object GetMinScalar(IObTransaction iObTransaction, string propertyName);
132 object GetMinScalar(IObTransaction iObTransaction, string propertyName, IObParameter iObParameter);
133 }
134 }
2
3 namespace DotNet.Frameworks.NParsing.Interface
4 {
5 public interface IObHelper<M>
6 {
7 /// <summary>
8 /// 检查是否存在
9 /// </summary>
10 /// <param name="iObParameter"></param>
11 /// <returns></returns>
12 bool Exists(IObParameter iObParameter);
13 bool Exists(IObTransaction iObTransaction, IObParameter iObParameter);
14
15 /// <summary>
16 /// 添加一个对象到数据库
17 /// </summary>
18 /// <param name="model"></param>
19 /// <returns></returns>
20 bool Add(M model);
21 bool Add(IObTransaction iObTransaction, M model);
22
23 /// <summary>
24 /// 从数据库删除一个对象
25 /// </summary>
26 /// <param name="iObParameter"></param>
27 /// <returns></returns>
28 bool Delete(IObParameter iObParameter);
29 bool Delete(IObTransaction iObTransaction, IObParameter iObParameter);
30
31 /// <summary>
32 /// 更新一个数据库对象
33 /// </summary>
34 /// <param name="model"></param>
35 /// <param name="iObParameter"></param>
36 /// <returns></returns>
37 bool Update(M model, IObParameter iObParameter);
38 bool Update(IObTransaction iObTransaction, M model, IObParameter iObParameter);
39
40 /// <summary>
41 /// 获取一个数据库对象
42 /// </summary>
43 /// <param name="iObParameter"></param>
44 /// <returns></returns>
45 M GetModel(IObParameter iObParameter);
46 M GetModel(IObTransaction iObTransaction, IObParameter iObParameter);
47
48 ///// <summary>
49 ///// 获取一个数据库对象的Json字符串
50 ///// </summary>
51 ///// <param name="iObParameter"></param>
52 ///// <returns></returns>
53 //string GetJsonModel(IObParameter iObParameter);
54 //string GetJsonModel(IObTransaction iObTransaction, IObParameter iObParameter);
55
56 /// <summary>
57 /// 获取一个数据库对象集合
58 /// </summary>
59 /// <returns></returns>
60 IList<M> GetList();
61 IList<M> GetList(IObParameter iObParameter);
62 IList<M> GetList(IObSort iObSort);
63 IList<M> GetList(IObParameter iObParameter, IObSort iObSort);
64 IList<M> GetList(IObTransaction iObTransaction);
65 IList<M> GetList(IObTransaction iObTransaction, IObParameter iObParameter);
66 IList<M> GetList(IObTransaction iObTransaction, IObSort iObSort);
67 IList<M> GetList(IObTransaction iObTransaction, IObParameter iObParameter, IObSort iObSort);
68
69 ///// <summary>
70 ///// 获取一个数据库对象集合的Json字符串
71 ///// </summary>
72 ///// <returns></returns>
73 //string GetJsonList();
74 //string GetJsonList(IObParameter iObParameter);
75 //string GetJsonList(string sortName, int sort);
76 //string GetJsonList(string sortName, int sort, IObParameter iObParameter);
77 //string GetJsonList(IObTransaction iObTransaction);
78 //string GetJsonList(IObTransaction iObTransaction, IObParameter iObParameter);
79 //string GetJsonList(IObTransaction iObTransaction, string sortName, int sort);
80 //string GetJsonList(IObTransaction iObTransaction, string sortName, int sort, IObParameter iObParameter);
81
82 /// <summary>
83 /// 获取一个数据库对象分页集合
84 /// </summary>
85 /// <param name="pageSize"></param>
86 /// <param name="pageIndex"></param>
87 /// <param name="iObSort"></param>
88 /// <param name="count"></param>
89 /// <returns></returns>
90 IList<M> GetList(int pageSize, int pageIndex, IObSort iObSort, out int count);
91 IList<M> GetList(int pageSize, int pageIndex, IObParameter iObParameter, IObSort iObSort, out int count);
92
93 ///// <summary>
94 ///// 获取一个数据库对象分页集合的Json字符串
95 ///// </summary>
96 ///// <param name="pageSize"></param>
97 ///// <param name="pageIndex"></param>
98 ///// <param name="sortName"></param>
99 ///// <param name="sort"></param>
100 ///// <param name="count"></param>
101 ///// <returns></returns>
102 //string GetJsonList(int pageSize, int pageIndex, string sortName, int sort, out int count);
103 //string GetJsonList(int pageSize, int pageIndex, string sortName, int sort, IObParameter iObParameter, out int count);
104
105 /// <summary>
106 /// 获取记录数
107 /// </summary>
108 /// <returns></returns>
109 int GetCount();
110 int GetCount(IObParameter iObParameter);
111 int GetCount(IObTransaction iObTransaction);
112 int GetCount(IObTransaction iObTransaction, IObParameter iObParameter);
113
114 /// <summary>
115 /// 获取某列最大值
116 /// </summary>
117 /// <param name="propertyName"></param>
118 /// <returns></returns>
119 object GetMaxScalar(string propertyName);
120 object GetMaxScalar(string propertyName, IObParameter iObParameter);
121 object GetMaxScalar(IObTransaction iObTransaction, string propertyName);
122 object GetMaxScalar(IObTransaction iObTransaction, string propertyName, IObParameter iObParameter);
123
124 /// <summary>
125 /// 获取某列最小值
126 /// </summary>
127 /// <param name="propertyName"></param>
128 /// <returns></returns>
129 object GetMinScalar(string propertyName);
130 object GetMinScalar(string propertyName, IObParameter iObParameter);
131 object GetMinScalar(IObTransaction iObTransaction, string propertyName);
132 object GetMinScalar(IObTransaction iObTransaction, string propertyName, IObParameter iObParameter);
133 }
134 }
参数组件接口代码
代码
1 using System.Collections.Generic;
2 using System.Data.Common;
3
4 namespace DotNet.Frameworks.NParsing.Interface
5 {
6 public interface IObParameter
7 {
8 /// <summary>
9 /// 值 null, DbTerm, DbNTerm
10 /// </summary>
11 object Value { get; set; }
12
13 /// <summary>
14 /// 平级兄弟列表
15 /// </summary>
16 IList<IObParameter> Brothers { get; set; }
17
18 /// <summary>
19 /// 0 无兄弟 1 AND 2 OR
20 /// </summary>
21 int BrotherType { get; set; }
22
23 /// <summary>
24 /// SQL条件语句
25 /// </summary>
26 string ToString(ref IList<DbParameter> dbParameters);
27
28 /// <summary>
29 /// 平级AND条件
30 /// </summary>
31 /// <param name="iObParameter"></param>
32 /// <returns></returns>
33 IObParameter And(IObParameter iObParameter);
34
35 /// <summary>
36 /// 平级OR条件
37 /// </summary>
38 /// <param name="iObParameter"></param>
39 /// <returns></returns>
40 IObParameter Or(IObParameter iObParameter);
41 }
42 }
2 using System.Data.Common;
3
4 namespace DotNet.Frameworks.NParsing.Interface
5 {
6 public interface IObParameter
7 {
8 /// <summary>
9 /// 值 null, DbTerm, DbNTerm
10 /// </summary>
11 object Value { get; set; }
12
13 /// <summary>
14 /// 平级兄弟列表
15 /// </summary>
16 IList<IObParameter> Brothers { get; set; }
17
18 /// <summary>
19 /// 0 无兄弟 1 AND 2 OR
20 /// </summary>
21 int BrotherType { get; set; }
22
23 /// <summary>
24 /// SQL条件语句
25 /// </summary>
26 string ToString(ref IList<DbParameter> dbParameters);
27
28 /// <summary>
29 /// 平级AND条件
30 /// </summary>
31 /// <param name="iObParameter"></param>
32 /// <returns></returns>
33 IObParameter And(IObParameter iObParameter);
34
35 /// <summary>
36 /// 平级OR条件
37 /// </summary>
38 /// <param name="iObParameter"></param>
39 /// <returns></returns>
40 IObParameter Or(IObParameter iObParameter);
41 }
42 }
排序组件接口代码
代码
1 using System.Collections.Generic;
2 using DotNet.Frameworks.NParsing.Common;
3
4 namespace DotNet.Frameworks.NParsing.Interface
5 {
6 public interface IObSort
7 {
8 /// <summary>
9 /// 排序字段列表
10 /// </summary>
11 IList<DbSort> List { get; set; }
12
13 /// <summary>
14 /// 添加一个排序参数
15 /// </summary>
16 /// <typeparam name="M"></typeparam>
17 /// <param name="propertyName">属性名</param>
18 /// <param name="isAsc"></param>
19 /// <returns></returns>
20 IObSort Add<M>(string propertyName, bool isAsc);
21
22 /// <summary>
23 /// 获取排序字符串
24 /// </summary>
25 /// <returns></returns>
26 string ToString();
27 }
28 }
2 using DotNet.Frameworks.NParsing.Common;
3
4 namespace DotNet.Frameworks.NParsing.Interface
5 {
6 public interface IObSort
7 {
8 /// <summary>
9 /// 排序字段列表
10 /// </summary>
11 IList<DbSort> List { get; set; }
12
13 /// <summary>
14 /// 添加一个排序参数
15 /// </summary>
16 /// <typeparam name="M"></typeparam>
17 /// <param name="propertyName">属性名</param>
18 /// <param name="isAsc"></param>
19 /// <returns></returns>
20 IObSort Add<M>(string propertyName, bool isAsc);
21
22 /// <summary>
23 /// 获取排序字符串
24 /// </summary>
25 /// <returns></returns>
26 string ToString();
27 }
28 }
事务组件接口代码
代码
1 using System;
2 using System.Data.Common;
3
4 namespace DotNet.Frameworks.NParsing.Interface
5 {
6 public interface IObTransaction : IDisposable
7 {
8 /// <summary>
9 /// 提交事务
10 /// </summary>
11 void Commit();
12
13 /// <summary>
14 /// 回滚事务
15 /// </summary>
16 void Rollback();
17
18 DbTransaction DbTransaction { get; }
19
20 string ConnectionString { get; }
21
22 string ProviderName { get;}
23 }
24 }
2 using System.Data.Common;
3
4 namespace DotNet.Frameworks.NParsing.Interface
5 {
6 public interface IObTransaction : IDisposable
7 {
8 /// <summary>
9 /// 提交事务
10 /// </summary>
11 void Commit();
12
13 /// <summary>
14 /// 回滚事务
15 /// </summary>
16 void Rollback();
17
18 DbTransaction DbTransaction { get; }
19
20 string ConnectionString { get; }
21
22 string ProviderName { get;}
23 }
24 }
NParsing的由来
今天是我为NParsing框架写的第一篇文章,所以我来解释一下NParsing名字的由来。
不怕大家笑话,我的英文学得不是很好,为本框架取名时差点把我难倒了。在偶然间,想到用框
架的原理来取名。
NParsing框架的核心技术是反射,生命源头是对象模型。而它就是将对象模型利用反射技术来转
变成SQL语言(SELECT、INSERT、DELETE、UPDATE)操作数据库。所以我把它叫做对象解析(Parsing)框架,因为是DotNet平台上开发的所以安照惯例前面加了“N
”,拼起来就是“NParsing”。然后上BAIDU搜了一下,结果还没人用。所以我先用上了。哈哈
至于框架的详细实现说明和框架使用说明,请继续关注我以后的文章。。。
NParsing框架下载
NParsing框架Demo下载