コード例 #1
0
        private List <DiffLogTableInfo> GetDiffTable(string sql, List <AgileParameter> parameters)
        {
            List <DiffLogTableInfo> result = new List <DiffLogTableInfo>();
            var whereSql = Regex.Replace(sql, ".* WHERE ", "", RegexOptions.Singleline);
            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);
        }
コード例 #2
0
        private List <DiffLogTableInfo> GetDiffTable(string sql, long?identity)
        {
            List <AgileParameter>   parameters = new List <AgileParameter>();
            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.SqlBuilder.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
                });
            }
        }