public T FindEntity <T>(Expression <Func <T, bool> > condition) where T : class, new() { using (var dbConnection = Connection) { string conditionsql = DatabaseCommon.DealExp <T>(condition.ClearLeft(), OperateType.Select).ToString(); var data = dbConnection.Query <T>(conditionsql); return(data.FirstOrDefault()); } }
/// <summary> /// 未实现 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="condition"></param> /// <returns></returns> public IQueryable <T> IQueryable <T>(Expression <Func <T, bool> > condition) where T : class, new() { using (var dbConnection = Connection) { string conditionsql = DatabaseCommon.DealExp <T>(condition.Body, OperateType.Select).ToString(); var data = dbConnection.Query <T>(string.Format(conditionsql)); return(data.AsQueryable()); } }
public int Delete <T>(Expression <Func <T, bool> > condition) where T : class, new() { bool isTrans = true; if (dbTransaction == null) { BeginTrans(); isTrans = false; } string conditionsql = DatabaseCommon.DealExp <T>(condition.Body, OperateType.Delete).ToString(); DbCommand cmd = dbTransaction.Connection.CreateCommand(); cmd.Transaction = dbTransaction; cmd.CommandText = conditionsql; cmd.ExecuteNonQuery(); if (!isTrans) { return(Commit()); } return(0); }
public IEnumerable <T> FindList <T>(Expression <Func <T, bool> > condition, string orderField, bool isAsc, int pageSize, int pageIndex, out int total) where T : class, new() { using (var dbConnection = Connection) { //string strSql = DatabaseCommon.DealExp<T>(condition, OperateType.Select).ToString(); //int num = (pageIndex - 1) * pageSize; //int num1 = (pageIndex) * pageSize; //orderField = "order by " + orderField; //StringBuilder sb = new StringBuilder(); //sb.Append("Select * From (Select ROW_NUMBER() Over (" + orderField + ")"); //sb.Append(" As rowNum, * From (" + strSql + ") As T ) As N Where rowNum > " + num + " And rowNum <= " + num1 + ""); //total = Convert.ToInt32(new DbHelper(dbConnection).ExecuteScalar(CommandType.Text, "Select Count(1) From (" + strSql + ") As t")); //var dataQuery = dbConnection.Query<T>(sb.ToString()); //return dataQuery.ToList(); string strSql = DatabaseCommon.DealExp <T>(condition, OperateType.Select). Append($"order by {orderField}").ToString(); //var dataQuery = dbConnection.Query<T>(strSql, buffered: false).AsQueryable(); var dataQuery = dbConnection.Query <T>(strSql); total = dataQuery.Count(); var data = dataQuery.Skip(pageSize * (pageIndex - 1)).Take(pageSize).AsQueryable(); return(data); } }