コード例 #1
0
        /// <summary>
        /// 验证表
        /// </summary>
        public static void Check(DataQuery item, string tableName, List <PropertyInfo> listInfo, List <Attribute> listAttribute)
        {
            try
            {
                if (item.Config.DesignModel == FastData.Core.Base.Config.CodeFirst)
                {
                    var table = new TableModel();

                    if (IsExistsTable(item, tableName))
                    {
                        //存在表
                        table = GetTable(item, tableName);
                        var model = PropertyCache.GetAttributesColumnInfo(tableName, listInfo);

                        if (model.Count >= table.Column.Count)
                        {
                            model.ForEach(p =>
                            {
                                var info   = table.Column.Find(a => string.Compare(a.Name, p.Name, true) == 0) ?? new ColumnModel();
                                var result = CheckModel.CompareTo(info, p);
                                if (result.IsUpdate)
                                {
                                    UpdateTable(item, result, tableName);
                                }
                            });
                        }
                        else
                        {
                            table.Column.ForEach(p =>
                            {
                                var info   = model.Find(a => string.Compare(a.Name, p.Name, true) == 0) ?? new ColumnModel();
                                var result = CheckModel.CompareTo(p, info);
                                if (result.IsUpdate)
                                {
                                    UpdateTable(item, result, tableName);
                                }

                                if (result.IsDelete)
                                {
                                    UpdateTable(item, result, tableName);
                                }
                            });
                        }

                        var comments = PropertyCache.GetAttributesTableInfo(listAttribute);
                        if (table.Comments != comments)
                        {
                            table.Comments = comments;
                            UpdateComments(item, table.Comments, tableName);
                        }
                    }
                    else
                    {
                        table.Column   = PropertyCache.GetAttributesColumnInfo(tableName, listInfo);
                        table.Name     = tableName;
                        table.Comments = PropertyCache.GetAttributesTableInfo(listAttribute);
                        AddTable(item, table.Column, tableName);
                        UpdateComments(item, table.Comments, tableName);
                    }
                }
            }
            catch (Exception ex)
            {
                var aop = FastUntility.Core.ServiceContext.Engine.Resolve <IFastAop>();
                if (aop != null)
                {
                    var context = new ExceptionContext();
                    context.ex   = ex;
                    context.name = "Code First table : " + tableName;
                    context.type = AopType.CodeFirst;
                    aop.Exception(context);
                }

                DbLog.LogException(item.Config.IsOutError, item.Config.DbType, ex, string.Format("Check_{0}", tableName), "");
            }
        }
コード例 #2
0
ファイル: BaseTable.cs プロジェクト: jason10wm/FastData.Core
        /// <summary>
        /// 验证表
        /// </summary>
        public static void Check(DataQuery item, string tableName, List <PropertyInfo> listInfo, List <Attribute> listAttribute)
        {
            try
            {
                if (item.Config.DesignModel == FastData.Core.Base.Config.CodeFirst)
                {
                    var table = new TableModel();

                    if (IsExistsTable(item, tableName))
                    {
                        //存在表
                        table = GetTable(item, tableName);
                        var model = PropertyCache.GetAttributesColumnInfo(tableName, listInfo);

                        if (model.Count >= table.Column.Count)
                        {
                            model.ForEach(p => {
                                var tempSql = new List <string>();
                                var info    = table.Column.Find(a => a.Name.ToLower() == p.Name.ToLower()) ?? new ColumnModel();
                                var result  = CheckModel.CompareTo <ColumnModel>(info, p);
                                if (result.IsUpdate)
                                {
                                    table.Column.Remove(p);
                                    table.Column.Add(result.Item);
                                    UpdateTable(item, result, tableName);
                                }
                            });
                        }
                        else
                        {
                            var tempColumn = new List <ColumnModel>();
                            tempColumn = table.Column;
                            tempColumn.ForEach(p => {
                                var tempSql = new List <string>();
                                var info    = table.Column.Find(a => a.Name.ToLower() == p.Name.ToLower()) ?? new ColumnModel();
                                var result  = CheckModel.CompareTo <ColumnModel>(p, info);
                                if (result.IsUpdate)
                                {
                                    table.Column.Remove(p);
                                    table.Column.Add(result.Item);
                                    UpdateTable(item, result, tableName);
                                }

                                if (result.IsDelete)
                                {
                                    model.Remove(p);
                                    UpdateTable(item, result, tableName);
                                }
                            });

                            table.Column = model;
                        }

                        var comments = PropertyCache.GetAttributesTableInfo(listAttribute);
                        if (table.Comments != comments)
                        {
                            table.Comments = comments;
                            UpdateComments(item, table.Comments, tableName);
                        }
                    }
                    else
                    {
                        table.Column   = PropertyCache.GetAttributesColumnInfo(tableName, listInfo);
                        table.Name     = tableName;
                        table.Comments = PropertyCache.GetAttributesTableInfo(listAttribute);
                        AddTable(item, table.Column, tableName);
                        UpdateComments(item, table.Comments, tableName);
                    }
                }
            }
            catch (Exception ex)
            {
                DbLog.LogException(item.Config.IsOutError, item.Config.DbType, ex, string.Format("Check_{0}", tableName), "");
            }
        }