Exemplo n.º 1
0
        /// <summary>
        /// Defines the column specifications by default
        /// </summary>
        /// <param name="type">Type of entity</param>
        /// <param name="create">An expression builder for a FluentMigrator.Expressions.CreateTableExpression</param>
        /// <param name="propertyInfo">Property info</param>
        /// <param name="canBeNullable">The value indicating whether this column is nullable</param>
        protected virtual void DefineByOwnType(Type type, CreateTableExpressionBuilder create, PropertyInfo propertyInfo, bool canBeNullable = false)
        {
            var propType = propertyInfo.PropertyType;

            if (Nullable.GetUnderlyingType(propType) is Type uType)
            {
                propType      = uType;
                canBeNullable = true;
            }

            if (!_typeMapping.ContainsKey(propType))
            {
                return;
            }

            if (type == typeof(string) || propType.FindInterfaces((t, o) => t.FullName?.Equals(o.ToString(), StringComparison.InvariantCultureIgnoreCase) ?? false, "System.Collections.IEnumerable").Any())
            {
                canBeNullable = true;
            }

            var column = create.WithColumn(NameCompatibilityManager.GetColumnName(type, propertyInfo.Name));

            _typeMapping[propType](column);

            if (canBeNullable)
            {
                create.Nullable();
            }
        }
        private static void DefineByOwnType(string columnName, Type propType, CreateTableExpressionBuilder create, bool canBeNullable = false)
        {
            if (string.IsNullOrEmpty(columnName))
            {
                throw new ArgumentException("The column name cannot be empty");
            }

            if (propType == typeof(string) || propType.FindInterfaces((t, o) => t.FullName?.Equals(o.ToString(), StringComparison.InvariantCultureIgnoreCase) ?? false, "System.Collections.IEnumerable").Length > 0)
            {
                canBeNullable = true;
            }

            var column = create.WithColumn(columnName);

            TypeMapping[propType](column);

            if (canBeNullable)
            {
                create.Nullable();
            }
        }