DBLayer,我最近开源的数据库轻量级 orm 框架,目前支持 sqlserver、mysql、oracle, 特别做了分页的封装。
这个框架从七八年前开始逐渐升级而来,也经历了不少项目,希望可以将大家从 sql 字符串中解放出来。
开源地址
https://github.com/wutao0315/DBLayer
访问代码案例
- varid = TheService.InsertEntitylong>(
- () =>new SysLog()
- {
- LogId = -1,
- LogContentJson ="测试",
- LogCreater ="测试",
- LogCreateTime = DateTime.Now,
- LogType ="1"
- });
- 分页操作
- /// <summary>
- /// 分页查询
- /// </summary>
- /// <param name="condition">查询条件</param>
- /// <returns></returns>
- publicIEnumerable Seach(SysUserCondition.Search condition)
- {
- varpage =newPager()
- {
- Condition = condition,
- Table ="sys_user",
- Key ="user_id",
- Order =string.Empty,
- Field ="*",
- WhereAction = (Condition, Where, Paramters) =>
- {
- if(!string.IsNullOrEmpty(Condition.UserName))
- {
- Where.Append("AND user_name LIKE @user_name ");
- Paramters.Add(base.CreateParameter("@user_name",string.Concat("%", Condition.UserName,"%")));
- }
- if(!string.IsNullOrEmpty(Condition.UserEmail))
- {
- Where.Append("AND user_email LIKE @user_email ");
- Paramters.Add(base.CreateParameter("@user_email",string.Concat("%", Condition.UserEmail,"%")));
- }
- if(!string.IsNullOrEmpty(Condition.UserMobile))
- {
- Where.Append("AND user_mobile LIKE @user_mobile ");
- Paramters.Add(base.CreateParameter("@user_mobile",string.Concat("%", Condition.UserMobile,"%")));
- }
- }
- };
- varresult =base.GetResultByPager(page);
- return result;
- }
推荐和 spring 配合使用,具体配置代码请进入源码查看。
同时在 spring 配置多个数据库连接,支持数据库连接字符串密码加密。只需要在 passwordKey 加入密钥
- <objectid="sql_wxius_string_server"type="DBLayer.Core.ConnectionString, DBLayer.Core"singleton="true">"Properties">
- "userid"value="sa"/>"password"value="***"/>"passwordKey"value=""/>"database"value="wxius"/>"datasource"value="."/>"ConnectionToken"value="Password=${password};Persist Security Info=True;User ID=${userid};Initial Catalog=${database};Data Source=${datasource};pooling=true;min pool size=5;max pool size=10"/>
- </object>
数据库唯一标识除了可以数据自动编码,还支持在代码端自动 生成 GUID 和 时间点。下面代码是 uuid, 时间点并按照顺序生成的自动编号
- <objectid="uuidGenerator"type="DBLayer.Persistence.UUIDGenerator, DBLayer.Persistence"singleton="true">3bits-->"workerId"value="1"/>10bits-->"regionId"value="1"/>04Nov2010 01:42:54GMT-->long)(DateTime.UtcNow -newDateTime(1970,1,1,0,0,0, DateTimeKind.Utc)).TotalMilliseconds-->"twepoch"value="1288834974657"/>
- </object>
来源: http://www.cnblogs.com/jweiswu/p/dblayer.html