using System;
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Mtxfw.Utility.DataAccess
{
///
/// 查询类
///
public partial class Sql : DbHelperSqlSugar
{
///
/// 查询所有
///
///
///
public List FindAll() where T : class, new()
{
return Db.Queryable().ToList();
}
///
/// 条件查询
///
///
///
///
///
///
public List FindAll(Expression> predicate, Expression> orderByPredicate, SqlSugar.OrderByType orderType) where T : class, new()
{
return Db.Queryable().Where(predicate).OrderBy(orderByPredicate, orderType).ToList();
}
///
/// 条件查询,带排序
///
///
///
///
///
public List FindAll(Expression> predicate, string orderByStr) where T : class, new()
{
return Db.Queryable().Where(predicate).OrderBy(orderByStr).ToList();
}
///
/// 根据主键查询
///
///
///
///
public T Find(int keyValue) where T : class, new()
{
return Db.Queryable().InSingle(keyValue);
}
///
/// 根据主键查询
///
///
///
///
public T Find(long keyValue) where T : class, new()
{
return Db.Queryable().InSingle(keyValue);
}
///
/// 查询第一条数据
///
///
///
///
public T FindFirst(Expression> predicate) where T : class, new()
{
return Db.Queryable().Where(predicate).First();
}
///
/// 查询第一条数据
///
///
///
///
public T FindFirst(Expression> predicate, string orderBy) where T : class, new()
{
return Db.Queryable().Where(predicate).OrderBy(orderBy).First();
}
///
/// 查询数据
///
///
///
///
public List Find(Expression> predicate) where T : class, new()
{
return Db.Queryable().Where(predicate).ToList();
}
///
/// 查询数据
///
///
///
///
public List Find(Expression> predicate, string orderBy) where T : class, new()
{
return Db.Queryable().Where(predicate).OrderBy(orderBy).ToList();
}
///
/// 获取记录条数
///
///
///
///
public int GetCount(Expression> predicate) where T : class, new()
{
return Db.Queryable().Where(predicate).Count();
}
///
/// 取前几条数据
///
///
///
///
///
///
///
public List FindTake(int count, Expression> predicate, Expression> orderByPredicate, SqlSugar.OrderByType orderType) where T : class, new()
{
return Db.Queryable().Where(predicate).OrderBy(orderByPredicate, orderType).Take(count).ToList();
}
///
/// 取前几条数据
///
///
///
///
///
///
public List FindTake(int count, Expression> predicate, string orderBy) where T : class, new()
{
return Db.Queryable().Where(predicate).OrderBy(orderBy).Take(count).ToList();
}
///
/// 取前几条数据
///
///
///
///
///
public List FindTake(int count, Expression> predicate) where T : class, new()
{
return Db.Queryable().Where(predicate).Take(count).ToList();
}
///
/// 执行事务
///
///
///
///
///
public List FindTran(Expression> predicate, string orderBy) where T : class, new()
{
var result = Db.Ado.UseTran>(() =>
{
return Db.Queryable().Where(predicate).OrderBy(orderBy).ToList();
throw new Exception("error haha");
});
return null;
}
///
/// 查询数据
///
///
///
///
///
public void FindTest(Expression> joinExpression) where T : class, new()
{
Db.Queryable(joinExpression);
}
}
}