Пример #1
0
        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="listModel"></param>
        public virtual void AddBatch(List <T> listModel)
        {
            try
            {
                List <ri_log> ba = new List <ri_log>();
                if (listModel != null && listModel.Count > 0)
                {
                    T             model   = listModel.FirstOrDefault();
                    var           ps      = model.GetType().GetProperties();
                    List <string> @colms  = new List <string>();
                    List <string> @params = new List <string>();

                    foreach (var p in ps)
                    {
                        if (!p.CustomAttributes.Any(x => x.AttributeType == typeof(PrimaryKeyAttribute)) && !p.CustomAttributes.Any(x => x.AttributeType == typeof(DBIgnoreAttribute)))
                        {
                            @colms.Add(string.Format("[{0}]", p.Name));
                            @params.Add(string.Format("@{0}", p.Name));
                        }
                    }
                    var sql = string.Format("INSERT INTO [{0}] ({1}) VALUES({2})", typeof(T).Name, string.Join(", ", @colms), string.Join(", ", @params));
                    using (var db = new DBHelper().CreateConnectionD())
                    {
                        db.Execute(sql, listModel, null, null, null);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #2
0
 /// <summary>
 /// 根据Id删除
 /// </summary>
 /// <param name="argWhere"></param>
 /// <returns></returns>
 public bool DeleteByWhere(string argWhere)
 {
     using (var db = new DBHelper().CreateConnectionD())
     {
         string sqlText = string.Format("Delete From {0} where 1=1 {1}", tableName, argWhere);
         int    res     = db.Execute(sqlText);
         return(res > 0 ? true : false);
     }
 }
Пример #3
0
 /// <summary>
 /// 根据Id删除
 /// </summary>
 /// <param name="argGuid"></param>
 /// <returns></returns>
 public bool Delete(string argGuid)
 {
     using (var db = new DBHelper().CreateConnectionD())
     {
         string sqlText = string.Format("Delete From {0} where {1} = '{2}'", tableName, keyName, argGuid);
         int    res     = db.Execute(sqlText); //dapper
         return(res > 0 ? true : false);
     }
 }