Home > Backend Development > C#.Net Tutorial > Detailed introduction to the latest open source DBLayer

Detailed introduction to the latest open source DBLayer

零下一度
Release: 2017-06-23 15:04:38
Original
1883 people have browsed it

DBLayer, my recent open source database lightweight ORM framework, currently supports sqlserver, mysql, oracle, and is specially encapsulated for paging.

This framework has been gradually upgraded since seven or eight years ago, and has also gone through many projects. I hope it can liberate everyone from SQL strings.

Open source address


Access code case

var id = TheService.InsertEntity<SysLog, long>(
        () => new SysLog()
        {
            LogId = -1,
            LogContentJson = "测试",
            LogCreater = "测试",
            LogCreateTime = DateTime.Now,
            LogType = "1"});
Copy after login
分页操作
Copy after login
        /// <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;
        }
Copy after login

It is recommended to be used in conjunction with spring. Please enter the source code to view the specific configuration code.

Configure multiple database connections in spring at the same time, supporting database connection string password encryption. You only need to add the key

  <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>
Copy after login

to the passwordKey. In addition to automatically encoding the data, the database unique identifier also supports automatic generation of GUID and time points on the code side. The following code is a uuid, time point and automatic number generated in sequence

  <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>
Copy after login

The above is the detailed content of Detailed introduction to the latest open source DBLayer. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template