最新开源DBLayer的详细介绍


本文摘自PHP中文网,作者零下一度,侵删。

DBLayer,我最近开源的数据库轻量级orm框架,目前支持sqlserver、mysql、oracle, 特别做了分页的封装。

这个框架从七八年前开始逐渐升级而来,也经历了不少项目,希望可以将大家从sql字符串中解放出来。

开源地址


访问代码案例

1

2

3

4

5

6

7

8

var id = TheService.InsertEntity<SysLog, long>(

        () => new SysLog()

        {

            LogId = -1,

            LogContentJson = "测试",

            LogCreater = "测试",

            LogCreateTime = DateTime.Now,

            LogType = "1"});

1

分页操作

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

/// <summary>/// 分页查询/// </summary>/// <param name="condition">查询条件</param>/// <returns></returns>public IEnumerable<SysUser> Seach(SysUserCondition.Search condition)

{var page = new Pager<SysUserCondition.Search>()

    {

        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, "%")));

            }

        }

    };var result = base.GetResultByPager<SysUser, SysUserCondition.Search>(page);return result;

}

推荐和spring 配合使用,具体配置代码请进入源码查看。

同时在spring 配置多个数据库连接,支持数据库连接字符串密码加密。只需要在 passwordKey加入密钥

1

2

3

4

5

6

7

8

9

10

11

12

<object id="sql_wxius_string_server" type="DBLayer.Core.ConnectionString, DBLayer.Core" singleton="true">

  <property name="Properties">

    <name-values>

      <add key="userid" value="sa" />

      <add key="password" value="***" />

      <add key="passwordKey" value="" />

      <add key="database" value="wxius" />

      <add key="datasource" value="." />

    </name-values>

  </property>

  <property name="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,时间点并按照顺序生成的自动编号

1

2

3

4

5

6

7

8

9

<object id="uuidGenerator" type="DBLayer.Persistence.UUIDGenerator, DBLayer.Persistence" singleton="true" >

  <!--workerId:区域(机房):3 bits-->

  <constructor-arg name="workerId" value="1"/>

  <!--regionId:机器编号:10 bits-->

  <constructor-arg name="regionId" value="1"/>

  <!--twepoch:基准时间:Thu, 04 Nov 2010 01:42:54 GMT-->

  <!--(long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds-->

  <constructor-arg name="twepoch" value="1288834974657"/>

</object>

以上就是最新开源DBLayer的详细介绍的详细内容!

相关阅读 >>

分享一些平时收藏和应用的开源代码

详解三种二维码的开源工具的不同之处

wpf materialdesign 示例开源项目介绍

详解c#把datatable中数据一次插入数据库的示例代码

最新开源DBLayer的详细介绍

.net存储pdf、word和excel到数据库的方法详解

asp保存二进制图片到access数据库

详细介绍一个.net开源权限管理系统

.net连接oracle出现ora-12514错误

详解vs2015自带localdb数据库用法实例

更多相关阅读请进入《DBLayer》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...