/// <summary> /// 返回的字段不能为NULL,最好就是 'Y' /// </summary> /// <param name="connInfo"></param> /// <param name="sql"></param> /// <param name="param"></param> /// <returns></returns> public static bool ExistsPrimitive(this DbContext connInfo, string sql, object param = null) { object result = connInfo.ExecuteScalar(sql, param); return(!SmartCrudHelper.IsNullOrDBNull(result)); }
public static int Insert <T>(this DbContext connInfo, T record, SqlFunction repl = null, Expression <Func <T, object> > onlyFields = null, string tableName = "") where T : new() { return(InsertPrimitive <T>(connInfo, new[] { record }, repl, SmartCrudHelper.GetPropertyNames <T>(onlyFields), tableName)); }
public static bool Exists <T>(this DbContext connInfo, RequestBase param, string tableName = "") where T : new() { return(ExistsInTable(connInfo, GetTableName <T>(connInfo.DbType, tableName), param)); }
/// <summary> /// 使用普通的SELECT语句,这个成本有点高 /// </summary> /// <param name="connInfo"></param> /// <param name="sql"></param> /// <param name="param"></param> /// <returns></returns> public static bool ExistsCount(this DbContext connInfo, string sql, object param = null) { return(0 < Count(connInfo, sql, param)); }
public static int Delete <T>(this DbContext connInfo, T record, Expression <Func <T, object> > matchFields = null, string tableName = "") where T : new() { return(DeletePrimitive <T>(connInfo, record, matchFields?.GetPropertyNames <T>(), tableName)); }
public static int DeletePrimitive <T>(this DbContext connInfo, T record, IEnumerable <string> matchFields = null, string tableName = "") where T : new() { return(connInfo.Db.Execute(connInfo.GetDeleteSql(typeof(T), tableName, matchFields), record, connInfo.Transaction, commandType: CommandType.Text)); }
public static IEnumerable <T> Select <T>(this DbContext db, string fields, RequestBase para, bool isExceptField, string tableName) where T : new() { return(db.SelectPrimitive <T>(para, fields.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries), isExceptField, tableName)); }
public static object SingleValue <T>(this DbContext connInfo, object[] pkValues, Expression <Func <T, object> > fieldName, string tableName = "", bool forUpdate = false) => SingleValuePrimitive <T>(connInfo, pkValues, SmartCrudHelper.GetPropertyName <T>(fieldName), tableName, forUpdate);
public static T Select <T>(this DbContext connInfo, object[] pkValues, Expression <Func <T, object> > onlyFields = null, bool isExceptField = false, string tableName = "", bool forUpdate = false) where T : new() { return(SelectPrimitive <T>(connInfo, pkValues, SmartCrudHelper.GetPropertyNames <T>(onlyFields), isExceptField, tableName, forUpdate: forUpdate)); }
public static IEnumerable <T> Select <T>(this DbContext connInfo, RequestBase param, Expression <Func <T, object> > onlyFields = null, bool isExceptField = false, string tableName = "") where T : new() { return(SelectPrimitive <T>(connInfo, param, onlyFields?.GetPropertyNames <T>(), isExceptField, tableName)); }
public static DataTable GetDataTable(this DbContext connInfo, string sql, RequestBase param, string filter = "", string orderStatement = "", Dictionary <string, object> condition = null) => SelectPageDataTable(connInfo, sql, param, 0, 0, filter, orderStatement, condition)?.DataList;
/// <summary> /// Chain操作中使用 /// </summary> /// <param name="cmdType"></param> /// <param name="sql"></param> /// <returns></returns> public static SqlChain StartSqlChain(this DbContext connInfo, string sql, CommandType cmdType = CommandType.Text) { return(new SqlChain(connInfo, cmdType, sql)); }
public static IEnumerable <T> SelectAll <T>(this DbContext connInfo, string tableName = "") where T : new() { return(connInfo.Db.Query <T>(connInfo.GetSelectSql <T>(true), transaction: connInfo.Transaction, commandType: CommandType.Text)); }
public static int UpdatePrimitive <T>(this DbContext connInfo, T record, SqlFunction repl = null, IEnumerable <string> onlyFields = null, string tableName = "") where T : new() { return(UpdatePrimitive <T>(connInfo, new[] { record }, repl, onlyFields, tableName)); }
public static int Delete <T>(this DbContext connInfo, IEnumerable <T> records, string tableName = "") where T : new() { return(connInfo.Db.Execute(connInfo.GetDeleteSql(typeof(T), tableName), records, connInfo.Transaction, commandType: CommandType.Text)); }
public static int Update <T>(this DbContext connInfo, IEnumerable <T> records, SqlFunction repl = null, Expression <Func <T, object> > onlyFields = null, string tableName = "") where T : new() { return(UpdatePrimitive <T>(connInfo, records, repl, onlyFields?.GetPropertyNames <T>(), tableName)); }
public static string TreatParaName(this DbContext connInfo, string paraName) => connInfo.DbType.TreatParaName(paraName);