Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="foreignKey"></param>
        /// <param name="table"></param>
        /// <returns></returns>
        private ForeignKeyInfo GetForeignKey(IForeignKey foreignKey, EFTableInfo table)
        {
            var result = new ForeignKeyInfo();

            result.Table  = table;
            result.Name   = foreignKey.Relational().Name;
            result.Column = table.GetColumn(foreignKey.GetColumnName());

            result.ReferenceTable  = GetReferenceTable(foreignKey);
            result.ReferenceColumn = result.ReferenceTable.GetColumn(foreignKey.GetReferenceColumnName());

            _migrateManager.CorrectName(result);
            return(result);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        private IEnumerable <UniqueKeyInfo> GetUniqueKeys(EFTableInfo table)
        {
            var indexes = table.Entity.GetIndexes().Where(w => w.IsUnique).ToList();

            foreach (var index in indexes)
            {
                var uniqueInfo = new UniqueKeyInfo();
                uniqueInfo.Table         = table;
                uniqueInfo.Name          = index.Relational()?.Name;
                uniqueInfo.UniqueColumns = index.Properties.Select(s => GetUniqueColumn(table, s)).ToList();

                _migrateManager.CorrectName(uniqueInfo);
                yield return(uniqueInfo);
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="table"></param>
        /// <param name="property"></param>
        /// <returns></returns>
        private ColumnInfo GetColumn(EFTableInfo table, IProperty property)
        {
            var columnRelational = property.Relational();

            var column = new ColumnInfo();

            column.Table        = table;
            column.Name         = columnRelational.ColumnName;
            column.Description  = property.PropertyInfo.GetSummary();
            column.Type         = new EFColumnTypeInfo(property);
            column.IsAllowNull  = property.IsNullable;
            column.DefaultValue = columnRelational.DefaultValue;
            column.Identity     = GetIdentity(property);

            _migrateManager.CorrectName(column);
            return(column);
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        private EFTableInfo ConvertToTableInfo(DbContext context, IEntityType entity)
        {
            var mapping   = entity.Relational();
            var tableInfo = new EFTableInfo();

            tableInfo.Context     = context;
            tableInfo.Entity      = entity;
            tableInfo.Name        = mapping.TableName;
            tableInfo.Schema      = mapping.Schema ?? _databaseTablesManager.DefaultSchema;
            tableInfo.ClrType     = entity.ClrType;
            tableInfo.Description = entity.ClrType.GetSummary();
            _migrateManager.CorrectName(tableInfo);

            tableInfo.Columns    = GetColumns(tableInfo);
            tableInfo.PrimaryKey = GetPrimaryKeyInfo(tableInfo);
            tableInfo.UniqueKeys = GetUniqueKeys(tableInfo).ToList();

            return(tableInfo);
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        private PrimaryKeyInfo GetPrimaryKeyInfo(EFTableInfo table)
        {
            var primary           = table.Entity.FindPrimaryKey();
            var primaryRelational = primary?.Relational();

            if (primaryRelational == null)
            {
                return(null);
            }

            var result = new PrimaryKeyInfo();

            result.Name  = primaryRelational.Name;
            result.Table = table;

            var prop = primary.Properties?.FirstOrDefault();
            var name = prop?.Relational()?.ColumnName;

            result.PrimaryColumn = table.GetColumn(name);

            _migrateManager.CorrectName(result);
            return(result);
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        private List <ForeignKeyInfo> GetForeignKeys(EFTableInfo table)
        {
            var foreignKeys = table.Entity.GetForeignKeys();

            return(foreignKeys.Select(s => GetForeignKey(s, table)).ToList());
        }
Example #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="table"></param>
 /// <param name="property"></param>
 /// <returns></returns>
 private ColumnInfo GetUniqueColumn(EFTableInfo table, IProperty property)
 {
     return(table.GetColumn(property.Relational().ColumnName));
 }
Example #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        private List <ColumnInfo> GetColumns(EFTableInfo table)
        {
            var props = table.Entity.GetProperties();

            return(props.Select(s => GetColumn(table, s)).ToList());
        }