Exemplo n.º 1
0
 /// <summary>
 /// 增量更新方法
 /// 例子:UpdateAdd(()=>new T{Field=1(或者-1)},m=>条件表示)
 /// </summary>
 /// <param name="updateFields">要修改的字段和增量值,不修改的字段不赋值</param>
 /// <param name="where">条件表达式</param>
 /// <returns></returns>
 public int UpdateAdd(Expression <Func <T> > updateFields, Expression <Func <T, bool> > where = null)
 {
     using (var conn = DbConnFactory.Open(DbName))
     {
         return(conn.UpdateAdd(updateFields, where));
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 根据条件更新部分字段
 /// </summary>
 /// <param name="fields"></param>
 /// <param name="predicate"></param>
 /// <returns></returns>
 public int Update(object fields, Expression <Func <T, bool> > predicate)
 {
     using (var conn = DbConnFactory.Open(DbName))
     {
         return(conn.Update(fields, predicate));
     }
 }
Exemplo n.º 3
0
 public int Count(Expression <Func <T, bool> > predicate)
 {
     using (var conn = DbConnFactory.Open(DbName))
     {
         return((int)conn.Count(predicate));
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 根据id更新一个实体
 /// </summary>
 /// <param name="entity">要更新的实体.</param>
 /// <returns>受影响的行数</returns>
 public int Update(T entity)
 {
     using (var conn = DbConnFactory.Open(DbName))
     {
         return(conn.Update(entity));
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// 通过id获取对象
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public T Single(long id)
 {
     using (var conn = DbConnFactory.Open(DbName))
     {
         return(conn.SingleById <T>(id));
     }
 }
Exemplo n.º 6
0
 public IEnumerable <T> Where(IEnumerable <long> ids)
 {
     using (var conn = DbConnFactory.Open(DbName))
     {
         return(conn.SelectByIds <T>(ids));
     }
 }
Exemplo n.º 7
0
 public T Single(Expression <Func <T, bool> > predicate)
 {
     using (var conn = DbConnFactory.Open(DbName))
     {
         return(conn.Single(predicate));
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// 根据id更新一个实体数组
 /// </summary>
 /// <param name="entitys">要更新的实体数组.</param>
 /// <returns>受影响的行数</returns>
 public int Update(IEnumerable <T> entitys)
 {
     using (var conn = DbConnFactory.Open(DbName))
     {
         if (DbSession.InDbTrasaction)
         {
             foreach (var item in entitys)
             {
                 conn.Update(item);
             }
         }
         else
         {
             using (var dt = conn.BeginTransaction())
             {
                 foreach (var item in entitys)
                 {
                     conn.Update(item);
                 }
                 dt.Commit();
             }
         }
     }
     return(entitys.Count());
 }
Exemplo n.º 9
0
 /// <summary>
 /// 获取所有记录
 /// </summary>
 /// <returns></returns>
 public IEnumerable <T> SelectAll()
 {
     using (var conn = DbConnFactory.Open(DbName))
     {
         return(conn.Select <T>());
     }
 }
Exemplo n.º 10
0
 /// <summary> 删除一个实体数组
 /// </summary>
 /// <param name="ids">要删除的实体id数组</param>
 /// <returns>受影响的行数</returns>
 public int Delete(IEnumerable <long> ids)
 {
     using (var conn = DbConnFactory.Open(DbName))
     {
         return(conn.DeleteByIds <T>(ids));
     }
 }
Exemplo n.º 11
0
 /// <summary> 删除一个实体
 /// </summary>
 /// <param name="id">要删除的实体id</param>
 /// <returns>受影响的行数</returns>
 public int Delete(long id)
 {
     using (var conn = DbConnFactory.Open(DbName))
     {
         return(conn.DeleteById <T>(id));
     }
 }
Exemplo n.º 12
0
 /// <summary> 插入一个实体数组
 /// </summary>
 /// <param name="entitys">要插入的实体数组</param>
 /// <returns>受影响的行数</returns>
 public int Insert(IEnumerable <T> entitys)
 {
     using (var conn = DbConnFactory.Open(DbName))
     {
         if (DbSession.InDbTrasaction)
         {
             foreach (var entity in entitys)
             {
                 entity.Id = conn.Insert(entity, true);
             }
         }
         else
         {
             using (var dt = conn.BeginTransaction())
             {
                 foreach (var entity in entitys)
                 {
                     entity.Id = conn.Insert(entity, true);
                 }
                 dt.Commit();
             }
         }
     }
     return(entitys.Count());
 }
Exemplo n.º 13
0
 public IEnumerable <T> Where(Expression <Func <T, bool> > predicate)
 {
     using (var conn = DbConnFactory.Open(DbName))
     {
         var result = conn.Select(predicate);
         return(result);
     }
 }
Exemplo n.º 14
0
 /// <summary> 插入一个实体
 /// </summary>
 /// <param name="entity">要插入的实体</param>
 /// <returns>受影响的行数</returns>
 public long Insert(T entity)
 {
     using (var conn = DbConnFactory.Open(DbName))
     {
         entity.Id = conn.Insert(entity, true);
         return(entity.Id);
     }
 }
Exemplo n.º 15
0
        public IEnumerable <T> Where(Action <SqlExp <T> > expression)
        {
            using (var conn = DbConnFactory.Open(DbName))
            {
                var exp = SqlExp <T> .GetSqlExp(conn);

                expression(exp);
                return(conn.Select(exp.GetExp()));
            }
        }
Exemplo n.º 16
0
        public T Single(Action <SqlExp <T> > expression)
        {
            using (var conn = DbConnFactory.Open(DbName))
            {
                var exp = SqlExp <T> .GetSqlExp(conn);

                expression(exp);
                return(conn.Single(exp.GetExp()));
            }
        }
Exemplo n.º 17
0
        public int Count(Action <SqlExp <T> > expression)
        {
            using (var conn = DbConnFactory.Open(DbName))
            {
                var exp = SqlExp <T> .GetSqlExp(conn);

                expression(exp);
                return((int)conn.Count <T>(exp.GetExp()));
            }
        }
Exemplo n.º 18
0
 public TKey Sum <TKey>(Expression <Func <T, object> > field, Expression <Func <T, bool> > predicate)
 {
     using (var conn = DbConnFactory.Open(DbName))
     {
         var exp = conn.GetDialectProvider().SqlExpression <T>();
         exp.Select(Sql.Sum(exp.ModelDef.GetFieldDefinition(field).FieldName));
         exp.And(predicate);
         var result = conn.Scalar <TKey>(exp);
         return(result);
     }
 }