Example #1
0
        /// <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));
        }
Example #2
0
 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));
 }
Example #3
0
 public static bool Exists <T>(this DbContext connInfo, RequestBase param, string tableName = "")
     where T : new()
 {
     return(ExistsInTable(connInfo, GetTableName <T>(connInfo.DbType, tableName), param));
 }
Example #4
0
 /// <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));
 }
Example #5
0
 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));
 }
Example #6
0
 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));
 }
Example #7
0
 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));
 }
Example #8
0
 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);
Example #9
0
 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));
 }
Example #10
0
 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));
 }
Example #11
0
 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;
Example #12
0
 /// <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));
 }
Example #13
0
 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));
 }
Example #14
0
 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));
 }
Example #15
0
 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));
 }
Example #16
0
 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));
 }
Example #17
0
 public static string TreatParaName(this DbContext connInfo, string paraName) => connInfo.DbType.TreatParaName(paraName);