示例#1
0
        public long Add <T>(T entity, EnumDBType?dbType = null) where T : EntityBase
        {
            var dbClient = DBProxy.CreateClient(dbType);
            var identify = dbClient.Insert(entity);

            return(identify);
        }
示例#2
0
        public T Get <T>(object id, EnumDBType?dbType = null) where T : EntityBase
        {
            var dbClient = DBProxy.CreateClient(dbType);
            var entity   = dbClient.Get <T>(id);

            return(entity);
        }
示例#3
0
        public IEnumerable <T> MenuGetList <T>(MenuGetListRequest req) where T : class
        {
            var client = DBProxy.CreateClient();
            var sql    = new StringBuilder(@"SELECT
                      sm.*,srmp.R_ID
                    FROM SS_MENU sm
                    JOIN SS_ROLE_MENU_PURVIEWCODE srmp
                      ON sm.M_CODE = srmp.MPC_CODE
                    INNER JOIN (SELECT
                        sru.R_ID
                      FROM SS_USER su
                      LEFT JOIN SS_ROLE_USER sru
                        ON su.U_ID = sru.U_ID
                      WHERE 1=1  ");
            var param  = new DynamicParameters();

            if (req.U_ID.HasValue)
            {
                sql.Append(" AND sru.U_ID = @U_ID");
                param.Add("@U_ID", req.U_ID);
            }

            sql.Append(@") t
            ON srmp.R_ID = t.R_ID
            WHERE sm.M_DISABLED = 0 ");

            if (!string.IsNullOrEmpty(req.M_NAME))
            {
                sql.Append(" AND sm.M_NAME_C LIKE @M_NAME_C");
                param.Add("@M_NAME_C", $"%{req.M_NAME}%");
            }
            return(client.Query <T>(sql.ToString(), param));
        }
示例#4
0
        public long Add <T>(T entity) where T : EntityBase
        {
            var dbClient = DBProxy.CreateClient();
            var identify = dbClient.Insert(entity);

            return(identify);
        }
示例#5
0
        public T Get <T>(object id) where T : EntityBase
        {
            var dbClient = DBProxy.CreateClient();
            var entity   = dbClient.Get <T>(id);

            return(entity);
        }
示例#6
0
        public IEnumerable <T> GetWhere <T>(Expression <Func <T, bool> > predicate, EnumDBType?dbType = null) where T : EntityBase
        {
            var client = DBProxy.CreateClient(dbType);
            // 拼接sql的方式批量插入
            Type Ts  = typeof(T);
            var  sql = $"select * from {Ts.Name.Replace("Entity", "")} where {SqlExpress.Instance.GetSql(predicate)}";

            return(client.Query <T>(sql));
        }
示例#7
0
        public long BulkInsert <T>(IEnumerable <T> entitys, string primaryKey, EnumDBType?dbType = null) where T : EntityBase
        {
            if (entitys.Count() > 1000)
            {
                //如果超过1000个 切成两份
                return(BulkInsert(entitys.Take(1000), primaryKey) + BulkInsert(entitys.Skip(1000), primaryKey));
            }

            // 拼接sql的方式批量插入
            Type Ts        = typeof(T);
            var  tableName = Ts.Name.Replace("Entity", "");

            StringBuilder sb = new StringBuilder();

            #region 拼接需要添加的字段
            sb.Append("INSERT INTO ").Append(tableName).Append(" (");
            IEnumerable <string> p = Ts.GetProperties().ToList().Where(x => !x.Name.Equals(primaryKey)).Select(x => x.Name);
            sb.Append(string.Join(",", p.ToArray())).Append(") ");
            #endregion

            #region  照顺序拼接值
            sb.Append("VALUES");
            entitys.ToList().ForEach(entity =>
            {
                sb.Append("(");
                foreach (var item in p)
                {
                    object o = Ts.GetProperty(item).GetValue(entity, null);
                    if (o == null)
                    {
                        sb.Append("null");
                    }
                    else if (o is string || o is DateTime || o is Guid)
                    {
                        sb.Append("'").Append(Convert.ToString(o)).Append("'");
                    }
                    else if (o is bool)
                    {
                        sb.Append(((bool)o ? 1 : 0));
                    }
                    else
                    {
                        sb.Append(Convert.ToString(o));
                    }
                    sb.Append(',');
                }
                sb.Replace(",", "),", sb.Length - 1, 1);
            });
            sb.Remove(sb.Length - 1, 1);
            #endregion


            var dbClient   = DBProxy.CreateClient(dbType);
            var iRowsCount = dbClient.Execute(sb.ToString(), new DynamicParameters());
            return(iRowsCount);
        }
示例#8
0
        public bool Update <T>(T entity, EnumDBType?dbType = null) where T : EntityBase
        {
            var dbClient = DBProxy.CreateClient(dbType);

            return(dbClient.Update(entity));
        }
示例#9
0
        public void BulkInsert <T>(IEnumerable <T> entitys, EnumDBType?dbType = null) where T : EntityBase
        {
            var dbClient = DBProxy.CreateClient(dbType);

            dbClient.Insert(entitys);
        }
示例#10
0
        public bool Update <T>(T entity) where T : EntityBase
        {
            var dbClient = DBProxy.CreateClient();

            return(dbClient.Update(entity));
        }
示例#11
0
        public void BulkInsert <T>(IEnumerable <T> entitys) where T : EntityBase
        {
            var dbClient = DBProxy.CreateClient();

            dbClient.Insert(entitys);
        }