Example #1
0
        /// <summary>
        /// 字段转成字典
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="filed"></param>
        /// <returns></returns>
        public static IDictionary <string, object> ToPropertyParam <TEntity>(this DbFiled <TEntity> filed) where TEntity : class
        {
            var property = ExpressionUtils.GetProperty(filed.Name);

            return(new Dictionary <string, object>()
            {
                { property, filed.Value }
            });
        }
Example #2
0
 /// <summary>
 /// 批量添加一个实体
 /// </summary>
 /// <param name="entities"></param>
 /// <param name="primaryKey"></param>
 /// <param name="commandTimeout"></param>
 /// <returns></returns>
 public bool Insert(IEnumerable <T> entities, Expression <Func <T, object> > primaryKey = null, int?commandTimeout = default(int?))
 {
     try
     {
         _context.Insert(entities, ExpressionUtils.GetProperty(primaryKey), commandTimeout);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #3
0
        /// <summary>
        /// 字段组转成字典
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="fileds"></param>
        /// <returns></returns>
        public static IDictionary <string, object> ToPropertyParam <TEntity>(this DbFiled <TEntity>[] fileds) where TEntity : class
        {
            IDictionary <string, object> param = new Dictionary <string, object>();

            foreach (var filed in fileds)
            {
                var property = ExpressionUtils.GetProperty(filed.Name);
                if (!param.ContainsKey(property))
                {
                    param.Add(property, filed.Value);
                }
            }
            return(param);
        }
Example #4
0
 /// <summary>
 /// 添加一个实体
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="primaryKey"></param>
 /// <returns></returns>
 public bool Insert(T entity, Expression <Func <T, object> > primaryKey = null)
 {
     return(_context.Insert(entity, ExpressionUtils.GetProperty(primaryKey)) > 0 ? true : false);
 }
Example #5
0
 /// <summary>
 /// 根据主键获取一个实体
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public T Get <TValue>(Expression <Func <T, object> > primaryKey, TValue value) where TValue : struct
 {
     return(_context.Get <T, TValue>(ExpressionUtils.GetProperty(primaryKey), value));
 }