溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

最新開(kāi)源DBLayer,數(shù)據(jù)庫(kù)操作也可以很簡(jiǎn)單

發(fā)布時(shí)間:2020-07-29 20:52:08 來(lái)源:網(wǎng)絡(luò) 閱讀:496 作者:zddnd 欄目:數(shù)據(jù)庫(kù)

DBLayer,我最近開(kāi)源的數(shù)據(jù)庫(kù)輕量級(jí)orm框架,目前支持sqlserver、mysql、oracle, 特別做了分頁(yè)的封裝。

這個(gè)框架從七八年前開(kāi)始逐漸升級(jí)而來(lái),也經(jīng)歷了不少項(xiàng)目,希望可以將大家從sql字符串中解放出來(lái)。

開(kāi)源地址

https://github.com/wutao0315/DBLayer

 

訪問(wèn)代碼案例

最新開(kāi)源DBLayer,數(shù)據(jù)庫(kù)操作也可以很簡(jiǎn)單

var id = TheService.InsertEntity<SysLog, long>(
        () => new SysLog()
        {
            LogId = -1,
            LogContentJson = "測(cè)試",
            LogCreater = "測(cè)試",
            LogCreateTime = DateTime.Now,
            LogType = "1"
        });

最新開(kāi)源DBLayer,數(shù)據(jù)庫(kù)操作也可以很簡(jiǎn)單

分頁(yè)操作

最新開(kāi)源DBLayer,數(shù)據(jù)庫(kù)操作也可以很簡(jiǎn)單

        /// <summary>
        /// 分頁(yè)查詢        /// </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;
        }

最新開(kāi)源DBLayer,數(shù)據(jù)庫(kù)操作也可以很簡(jiǎn)單

推薦和spring 配合使用,具體配置代碼請(qǐng)進(jìn)入源碼查看。

同時(shí)在spring 配置多個(gè)數(shù)據(jù)庫(kù)連接,支持?jǐn)?shù)據(jù)庫(kù)連接字符串密碼加密。只需要在 passwordKey加入密鑰

最新開(kāi)源DBLayer,數(shù)據(jù)庫(kù)操作也可以很簡(jiǎn)單

  <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>

最新開(kāi)源DBLayer,數(shù)據(jù)庫(kù)操作也可以很簡(jiǎn)單

數(shù)據(jù)庫(kù)唯一標(biāo)識(shí)除了可以數(shù)據(jù)自動(dòng)編碼,還支持在代碼端自動(dòng) 生成 GUID 和 時(shí)間點(diǎn)。下面代碼是uuid,時(shí)間點(diǎn)并按照順序生成的自動(dòng)編號(hào)

最新開(kāi)源DBLayer,數(shù)據(jù)庫(kù)操作也可以很簡(jiǎn)單

  <object id="uuidGenerator" type="DBLayer.Persistence.UUIDGenerator, DBLayer.Persistence" singleton="true" >
    <!--workerId:區(qū)域(機(jī)房):3 bits-->
    <constructor-arg name="workerId" value="1"/>
    <!--regionId:機(jī)器編號(hào):10 bits-->
    <constructor-arg name="regionId" value="1"/>
    <!--twepoch:基準(zhǔn)時(shí)間: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>

最新開(kāi)源DBLayer,數(shù)據(jù)庫(kù)操作也可以很簡(jiǎn)單


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI