/// <summary> /// 更新 /// </summary> /// <param name="entity">实体</param> /// <returns></returns> public static WhereHelper <T> Update(T entity) { entity.Validate(); WhereHelper <T> wherehelper = new WhereHelper <T>(); List <PropertyInfo> properties = MemberInfoEx.GetPropertyCache <T>(); properties.ForEach(x => wherehelper.ParaAppend(x.Name, x.FastGetValue(entity), false)); return(wherehelper.StringAppend(_UpdateSql, " WHERE ")); }
/// <summary> /// 执行Sql语句,返回实体数据 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="whereHelper">wherehelper</param> /// <returns><see cref="T"/></returns> public static T GetEntity <T>(this WhereHelper <T> whereHelper) where T : BaseEntity, new() { using (var reader = whereHelper.GetDataReader()) { try { if (reader.HasRows) { if (reader.Read()) { return(reader.GetEntity <T>()); } } } catch (Exception) { reader.Close(); throw; } } return(default);
/// <summary> /// 执行Sql语句,判断数据是否存在 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="whereHelper">wherehelper</param> /// <returns>存在结果</returns> public static bool Exists <T>(this WhereHelper <T> whereHelper) where T : BaseEntity, new() { return(whereHelper.GetScalar() != null); }
/// <summary> /// 执行Sql语句,返回单行数据 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="whereHelper">wherehelper</param> /// <returns><see cref="DbDataReader"/></returns> public static DbDataReader GetDataReader <T>(this WhereHelper <T> whereHelper) where T : BaseEntity, new() => DBHelper.GetDataReader(whereHelper.ToString(), CommandBehavior.Default, whereHelper.ToDBArry());
/// <summary> /// 执行Sql语句,返回首行首列 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="whereHelper">wherehelper</param> /// <returns><see cref="object"/></returns> public static object GetScalar <T>(this WhereHelper <T> whereHelper) where T : BaseEntity, new() => DBHelper.GetScalar(whereHelper.ToString(), CommandType.Text, whereHelper.ToDBArry());
/// <summary> /// 执行Sql语句 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="whereHelper">wherehelper</param> /// <returns><see cref="int"/> 受影响行数</returns> public static int RunSql <T>(this WhereHelper <T> whereHelper) where T : BaseEntity, new() => DBHelper.RunSql(whereHelper.ToString(), CommandType.Text, whereHelper.ToDBArry());
/// <summary> /// 执行获取DataTable /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="whereHelper">wherehelper</param> /// <returns><see cref="DataTable"/></returns> public static DataTable GetDataTable <T>(this WhereHelper <T> whereHelper) where T : BaseEntity, new() => DBHelper.GetDataTable(whereHelper.ToString(), CommandType.Text, whereHelper.ToDBArry());
/// <summary> /// 比较符 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="wherehelper">wherehelper</param> /// <param name="value">值</param> /// <returns><see cref="WhereHelper{T}"/></returns> public static WhereHelper <T> LessThan <T>(this WhereHelper <T> wherehelper, object value) where T : BaseEntity, new() => wherehelper.StringAppend(" < ", WhereHelper <T> .TurnParaToWherePrefix(wherehelper.PreField)).ParaAppend(string.Empty, value);
/// <summary> /// 字段 like 值% /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="wherehelper">wherehelper</param> /// <param name="field">字段</param> /// <param name="value">值</param> /// <returns><see cref="WhereHelper{T}"/></returns> public static WhereHelper <T> FieldStartWith <T>(this WhereHelper <T> wherehelper, string field, object value) where T : BaseEntity, new() => wherehelper.StringAppend(" ", field, " Like ", WhereHelper <T> .TurnParaToWherePrefix(field)).ParaAppend(field, $"{value}%");
/// <summary> /// 字段=值 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="wherehelper">wherehelper</param> /// <param name="field">字段</param> /// <param name="value">值</param> /// <returns><see cref="WhereHelper{T}"/></returns> public static WhereHelper <T> FieldEqual <T>(this WhereHelper <T> wherehelper, string field, object value) where T : BaseEntity, new() => wherehelper.StringAppend(" ", field, "=", WhereHelper <T> .TurnParaToWherePrefix(field)).ParaAppend(field, value);
/// <summary> /// 并且 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="wherehelper">wherehelper</param> /// <returns><see cref="WhereHelper{T}"/></returns> public static WhereHelper <T> And <T>(this WhereHelper <T> wherehelper) where T : BaseEntity, new() => wherehelper.StringAppend(" And ");