** 描述:验证失败,则抛出异常 ** 创始时间:2015-7-19 ** 修改时间:- ** 作者:sunkaixuan ** 修改人:sunkaixuan ** 使用说明:
 public IDeleteable<T> Where(List<T> deleteObjs)
 {
     if (deleteObjs == null || deleteObjs.Count() == 0)
     {
         Where(SqlBuilder.SqlFalse);
         return this;
     }
     string tableName = this.Context.EntityMaintenance.GetTableName<T>();
     var primaryFields = this.GetPrimaryKeys();
     var isSinglePrimaryKey = primaryFields.Count == 1;
     Check.Exception(primaryFields.IsNullOrEmpty(), string.Format("Table {0} with no primarykey", tableName));
     if (isSinglePrimaryKey)
     {
         List<object> primaryKeyValues = new List<object>();
         var primaryField = primaryFields.Single();
         foreach (var deleteObj in deleteObjs)
         {
             var entityPropertyName = this.Context.EntityMaintenance.GetPropertyName<T>(primaryField);
             var columnInfo = EntityInfo.Columns.Single(it => it.PropertyName.Equals(entityPropertyName, StringComparison.CurrentCultureIgnoreCase));
             var value = columnInfo.PropertyInfo.GetValue(deleteObj, null);
             primaryKeyValues.Add(value);
         }
         if (primaryKeyValues.Count < 10000)
         {
             var inValueString = primaryKeyValues.ToArray().ToJoinSqlInVals();
             Where(string.Format(DeleteBuilder.WhereInTemplate, SqlBuilder.GetTranslationColumnName(primaryFields.Single()), inValueString));
         }
         else
         {
             if (DeleteBuilder.BigDataInValues == null)
                 DeleteBuilder.BigDataInValues = new List<object>();
             DeleteBuilder.BigDataInValues.AddRange(primaryKeyValues);
             DeleteBuilder.BigDataFiled = primaryField;
         }
     }
     else
     {
         StringBuilder whereInSql = new StringBuilder();
         foreach (var deleteObj in deleteObjs)
         {
             StringBuilder orString = new StringBuilder();
             var isFirst = deleteObjs.IndexOf(deleteObj) == 0;
             if (!isFirst)
             {
                 orString.Append(DeleteBuilder.WhereInOrTemplate + UtilConstants.Space);
             }
             int i = 0;
             StringBuilder andString = new StringBuilder();
             foreach (var primaryField in primaryFields)
             {
                 if (i != 0)
                     andString.Append(DeleteBuilder.WhereInAndTemplate + UtilConstants.Space);
                 var entityPropertyName = this.Context.EntityMaintenance.GetPropertyName<T>(primaryField);
                 var columnInfo = EntityInfo.Columns.Single(it => it.PropertyName == entityPropertyName);
                 var entityValue = columnInfo.PropertyInfo.GetValue(deleteObj, null);
                 var tempequals = DeleteBuilder.WhereInEqualTemplate;
                 if (this.Context.CurrentConnectionConfig.MoreSettings != null && this.Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar == true) 
                 {
                     tempequals = "\"{0}\"='{1}' ";
                 }
                 if (this.Context.CurrentConnectionConfig.DbType == DbType.Oracle)
                 {
                     if (entityValue != null && UtilMethods.GetUnderType(entityValue.GetType()) == UtilConstants.DateType)
                     {
                         andString.AppendFormat("\"{0}\"={1} ", primaryField.ToUpper(), "to_date('" + entityValue.ObjToDate().ToString("yyyy-MM-dd HH:mm:ss") + "', 'YYYY-MM-DD HH24:MI:SS') ");
                     }
                     else
                     {
                         andString.AppendFormat(tempequals, primaryField.ToUpper(), entityValue);
                     }
                 }
                 else if (this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL && (this.Context.CurrentConnectionConfig.MoreSettings == null || this.Context.CurrentConnectionConfig.MoreSettings?.PgSqlIsAutoToLower == true))
                 {
                     andString.AppendFormat("\"{0}\"={1} ", primaryField.ToLower(), new PostgreSQLExpressionContext().GetValue(entityValue));
                 }
                 else if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer && entityValue != null && UtilMethods.GetUnderType(entityValue.GetType()) == UtilConstants.DateType) 
                 {
                     andString.AppendFormat("\"{0}\"={1} ", primaryField,$"'{entityValue.ObjToDate().ToString("yyyy-MM-dd HH:mm:ss.fff")}'");
                 }
                 else
                 {
                     andString.AppendFormat(tempequals, primaryField, entityValue);
                 }
                 ++i;
             }
             orString.AppendFormat(DeleteBuilder.WhereInAreaTemplate, andString);
             whereInSql.Append(orString);
         }
         Where(string.Format(DeleteBuilder.WhereInAreaTemplate, whereInSql.ToString()));
     }
     return this;
 }
 public override bool BackupDataBase(string databaseName, string fullFileName)
 {
     Check.ThrowNotSupportedException("MySql BackupDataBase NotSupported");
     return false;
 }
Example #3
0
        private List <DiffLogTableInfo> GetDiffTable(string sql, long?identity)
        {
            List <SugarParameter>   parameters = new List <SugarParameter>();
            List <DiffLogTableInfo> result     = new List <DiffLogTableInfo>();
            var whereSql = string.Empty;
            List <IConditionalModel> cons = new List <IConditionalModel>();

            if (identity != null && identity > 0 && GetIdentityKeys().HasValue())
            {
                var fieldName = GetIdentityKeys().Last();
                cons.Add(new ConditionalModel()
                {
                    ConditionalType = ConditionalType.Equal, FieldName = fieldName, FieldValue = identity.ToString()
                });
            }
            else
            {
                foreach (var item in this.EntityInfo.Columns.Where(it => it.IsIgnore == false && GetPrimaryKeys().Any(pk => pk.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))))
                {
                    var fielddName = item.DbColumnName;
                    var fieldValue = this.EntityInfo.Columns.FirstOrDefault(it => it.PropertyName == item.PropertyName).PropertyInfo.GetValue(this.InsertObjs.Last(), null).ObjToString();
                    cons.Add(new ConditionalModel()
                    {
                        ConditionalType = ConditionalType.Equal, FieldName = fielddName, FieldValue = fieldValue
                    });
                }
            }
            Check.Exception(cons.IsNullOrEmpty(), "Insertable.EnableDiffLogEvent need primary key");
            var sqlable = this.Context.Utilities.ConditionalModelToSql(cons);

            whereSql = sqlable.Key;
            parameters.AddRange(sqlable.Value);
            var dt = this.Context.Queryable <T>().Where(whereSql).AddParameters(parameters).ToDataTable();

            if (dt.Rows != null && dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    DiffLogTableInfo item = new DiffLogTableInfo();
                    item.TableDescription = this.EntityInfo.TableDescription;
                    item.TableName        = this.EntityInfo.DbTableName;
                    item.Columns          = new List <DiffLogColumnInfo>();
                    foreach (DataColumn col in dt.Columns)
                    {
                        DiffLogColumnInfo addItem = new DiffLogColumnInfo();
                        addItem.Value             = row[col.ColumnName];
                        addItem.ColumnName        = col.ColumnName;
                        addItem.ColumnDescription = this.EntityInfo.Columns.First(it => it.DbColumnName.Equals(col.ColumnName, StringComparison.CurrentCultureIgnoreCase)).ColumnDescription;
                        item.Columns.Add(addItem);
                    }
                    result.Add(item);
                }
                return(result);
            }
            else
            {
                DiffLogTableInfo diffTable = new DiffLogTableInfo();
                diffTable.TableName        = this.EntityInfo.DbTableName;
                diffTable.TableDescription = this.EntityInfo.TableDescription;
                diffTable.Columns          = this.EntityInfo.Columns.Where(it => it.IsIgnore == false).Select(it => new DiffLogColumnInfo()
                {
                    ColumnDescription = it.ColumnDescription,
                    ColumnName        = it.DbColumnName,
                    Value             = it.PropertyInfo.GetValue(this.InsertObjs.Last(), null)
                }).ToList();
                return(new List <DiffLogTableInfo>()
                {
                    diffTable
                });
            }
        }
 public IDeleteable<T> Where(T deleteObj)
 {
     Check.Exception(GetPrimaryKeys().IsNullOrEmpty(), "Where(entity) Primary key required");
     Where(new List<T>() { deleteObj });
     return this;
 }
Example #5
0
 void ThrowTrue(bool isError)
 {
     Check.Exception(isError, ErrorMessage.GetThrowMessage(expression.ToString() + "no support", "不支持表达式" + expression.ToString() + " 1.检查当前表达式中的别名是否与Mapper中的一致 2.目前只支持 1对1 Mapper下的 Where "));
 }
Example #6
0
 void Error01()
 {
     Check.Exception(mappers == null, ErrorMessage.GetThrowMessage(expression.ToString() + "no support", "当前表达式" + expression.ToString() + "必须在Mapper之后使用"));
 }
 public virtual IUpdateable <T> Updateable <T>(List <T> UpdateObjs) where T : class, new()
 {
     Check.ArgumentNullException(UpdateObjs, "Updateable.UpdateObjs can't be null");
     return(Updateable(UpdateObjs.ToArray()));
 }
 public virtual IInsertable <T> Insertable <T>(List <T> insertObjs) where T : class, new()
 {
     Check.ArgumentNullException(insertObjs, "Insertable.insertObjs can't be null");
     return(this.Context.Insertable(insertObjs.ToArray()));
 }
 public virtual ISugarQueryable <T> Union <T>(List <ISugarQueryable <T> > queryables) where T : class, new()
 {
     Check.Exception(queryables.IsNullOrEmpty(), "Union.queryables is null ");
     return(Union(queryables.ToArray()));
 }