This commit is contained in:
sunkaixuan
2018-04-23 10:38:38 +08:00
parent 71d970a574
commit 0f8f029b22
2 changed files with 23 additions and 14 deletions

View File

@@ -243,7 +243,7 @@ namespace OrmTest.Demo
{
var db = GetInstance();
var dbTime = db.GetDate();
var getAll = db.Queryable<Student>().ToList();
var getAll = db.Queryable<Student>().Select<object>("*").ToList();
var getAllOrder = db.Queryable<Student>().OrderBy(it => it.Id).OrderBy(it => it.Name, OrderByType.Desc).ToList();
var getId = db.Queryable<Student>().Select(it => it.Id).ToList();
var getNew = db.Queryable<Student>().Where(it => it.Id == 1).Select(it => new { id = SqlFunc.IIF(it.Id == 0, 1, it.Id), it.Name, it.SchoolId }).ToList();

View File

@@ -28,14 +28,18 @@ namespace SqlSugar
{
return Context.Queryable<T>().ToList();
}
public T GetSingle<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
{
return Context.Queryable<T>().Single(whereExpression);
}
public List<T> GetList<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
{
return Context.Queryable<T>().Where(whereExpression).ToList();
}
public List<T> GetPageList<T>(Expression<Func<T, bool>> whereExpression,PageModel page) where T : class, new()
public List<T> GetPageList<T>(Expression<Func<T, bool>> whereExpression, PageModel page) where T : class, new()
{
int count = 0;
var result= Context.Queryable<T>().Where(whereExpression).ToPageList(page.PageIndex,page.PageSize,ref count);
var result = Context.Queryable<T>().Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count);
page.PageCount = count;
return result;
}
@@ -109,7 +113,7 @@ namespace SqlSugar
{
return Context.Queryable<T>().InSingle(id);
}
public List<T> GetList()
public List<T> GetList()
{
return Context.Queryable<T>().ToList();
}
@@ -117,6 +121,10 @@ namespace SqlSugar
{
return Context.Queryable<T>().Where(whereExpression).ToList();
}
public T GetSingle(Expression<Func<T, bool>> whereExpression)
{
return Context.Queryable<T>().Single(whereExpression);
}
public List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page)
{
int count = 0;
@@ -135,20 +143,21 @@ namespace SqlSugar
{
return Context.Queryable<T>().Where(whereExpression).Any();
}
public int Count(Expression<Func<T,bool>> whereExpression){
return Context.Queryable<T>().Where(whereExpression).Count();
public int Count(Expression<Func<T, bool>> whereExpression)
{
return Context.Queryable<T>().Where(whereExpression).Count();
}
public bool Insert(T insertObj)
public bool Insert(T insertObj)
{
return this.Context.Insertable(insertObj).ExecuteCommand() > 0;
}
public int InsertReturnIdentity(T insertObj)
public int InsertReturnIdentity(T insertObj)
{
return this.Context.Insertable(insertObj).ExecuteReturnIdentity();
}
public bool InsertRange(T[] insertObjs)
public bool InsertRange(T[] insertObjs)
{
return this.Context.Insertable(insertObjs).ExecuteCommand() > 0;
}
@@ -156,11 +165,11 @@ namespace SqlSugar
{
return this.Context.Insertable(insertObjs).ExecuteCommand() > 0;
}
public bool Update(T updateObj)
public bool Update(T updateObj)
{
return this.Context.Updateable(updateObj).ExecuteCommand() > 0;
}
public bool Update(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression)
public bool Update(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression)
{
return this.Context.Updateable<T>().UpdateColumns(columns).Where(whereExpression).ExecuteCommand() > 0;
}
@@ -168,11 +177,11 @@ namespace SqlSugar
{
return this.Context.Deleteable<T>().Where(deleteObj).ExecuteCommand() > 0;
}
public bool Delete(Expression<Func<T, bool>> whereExpression)
public bool Delete(Expression<Func<T, bool>> whereExpression)
{
return this.Context.Deleteable<T>().Where(whereExpression).ExecuteCommand() > 0;
}
public bool DeleteById(dynamic id)
public bool DeleteById(dynamic id)
{
return this.Context.Deleteable<T>().In(id).ExecuteCommand() > 0;
}