Example #1
0
 public BasicEntityTable()
 {
     Columns = new ISchemaColumn[]
     {
         new SchemaColumn(nameof(BasicEntity.Name), 10,
                          typeof(BasicEntity).GetProperty(nameof(BasicEntity.Name)).PropertyType),
         new SchemaColumn(nameof(BasicEntity.City), 11,
                          typeof(BasicEntity).GetProperty(nameof(BasicEntity.City)).PropertyType),
         new SchemaColumn(nameof(BasicEntity.Country), 12,
                          typeof(BasicEntity).GetProperty(nameof(BasicEntity.Country)).PropertyType),
         new SchemaColumn(nameof(BasicEntity.Population), 13,
                          typeof(BasicEntity).GetProperty(nameof(BasicEntity.Population)).PropertyType),
         new SchemaColumn(nameof(BasicEntity.Self), 14,
                          typeof(BasicEntity).GetProperty(nameof(BasicEntity.Self)).PropertyType),
         new SchemaColumn(nameof(BasicEntity.Money), 15,
                          typeof(BasicEntity).GetProperty(nameof(BasicEntity.Money)).PropertyType),
         new SchemaColumn(nameof(BasicEntity.Month), 16,
                          typeof(BasicEntity).GetProperty(nameof(BasicEntity.Month)).PropertyType),
         new SchemaColumn(nameof(BasicEntity.Time), 17,
                          typeof(BasicEntity).GetProperty(nameof(BasicEntity.Time)).PropertyType),
         new SchemaColumn(nameof(BasicEntity.Id), 18,
                          typeof(BasicEntity).GetProperty(nameof(BasicEntity.Id)).PropertyType),
         new SchemaColumn(nameof(BasicEntity.NullableValue), 19,
                          typeof(BasicEntity).GetProperty(nameof(BasicEntity.NullableValue)).PropertyType)
     };
 }
        private static void PrepareAndThrowUnknownColumnExceptionMessage(string indetifier, ISchemaColumn[] columns)
        {
            var library    = new TransitionLibrary();
            var candidates = new StringBuilder();

            var candidatesColumns = columns.Where(col =>
                                                  library.Soundex(col.ColumnName) == library.Soundex(indetifier) ||
                                                  library.LevenshteinDistance(col.ColumnName, indetifier).Value < 3).ToArray();

            for (int i = 0; i < candidatesColumns.Length - 1; i++)
            {
                ISchemaColumn candidate = candidatesColumns[i];
                candidates.Append(candidate.ColumnName);
                candidates.Append(", ");
            }

            if (candidatesColumns.Length > 0)
            {
                candidates.Append(candidatesColumns[candidatesColumns.Length - 1].ColumnName);

                throw new UnknownColumnException($"Column '{indetifier}' could not be found. Did you mean to use [{candidates.ToString()}]?");
            }

            throw new UnknownColumnException($"Column {indetifier} could not be found.");
        }
Example #3
0
        public ISchemaColumn GetColumn(string columnName)
        {
            ISchemaColumn column = null;

            foreach (var table in _orders)
            {
                var tmpColumn = _tables[table].Item2.Columns.SingleOrDefault(col => col.ColumnName == columnName);

                if (column != null)
                {
                    throw new NotSupportedException("Multiple column with the same identifier");
                }

                if (tmpColumn == null)
                {
                    continue;
                }

                column = tmpColumn;
            }

            if (column == null)
            {
                throw new NotSupportedException("No such column.");
            }

            return(column);
        }
Example #4
0
        public bool TryGetColumn(string name, out ISchemaColumn column)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            return(columns.TryGetValue(name, out column));
        }
Example #5
0
 static void ColumnFormatter(DbConnectionProvider provider, ISchemaColumn column, StringBuilder builder)
 {
     builder.AppendFormat("    {0} {1}", provider.NormalizeSymbol(column.Name), MsSqlHelper.GetDbTypeString(column));
     if (column.IsPrimary)
     {
         builder.Append(" Not Null");
     }
     else
     {
         builder.Append(" Null");
     }
 }
Example #6
0
        public static string GetDbTypeString(ISchemaColumn column)
        {
            if (column == null)
            {
                throw new ArgumentNullException(nameof(column));
            }

            switch (column.DbType)
            {
            case DbType.Byte:
            case DbType.Boolean:
            case DbType.Date:
            case DbType.DateTime:
            case DbType.Double:
            case DbType.Guid:
            case DbType.Int16:
            case DbType.Int32:
            case DbType.Int64:
            case DbType.SByte:
            case DbType.Single:
            case DbType.Time:
            case DbType.UInt16:
            case DbType.UInt32:
            case DbType.UInt64:
            case DbType.Xml:
            case DbType.DateTime2:
            case DbType.DateTimeOffset:
                return(string.Format("{0}", ConvertToSqlType(column.DbType)));

            case DbType.AnsiString:
            case DbType.Binary:
            case DbType.Currency:
            case DbType.Decimal:
            case DbType.String:
            case DbType.VarNumeric:
            case DbType.AnsiStringFixedLength:
            case DbType.StringFixedLength:
                return(string.Format("{0}({1})", ConvertToSqlType(column.DbType), column.MaxLength == -1 ? "Max" : column.MaxLength.ToString()));

            default:
                throw new ArgumentException(string.Format("unknown DbType:{0}", column.DbType));
            }
        }
Example #7
0
        private static string GetColumnCommand(ISchemaTable table, ISchemaColumn column)
        {
            var builder = new StringBuilder();

            builder.AppendFormat("[{0}] {1}", column.Name, MsSqlHelper.GetDbTypeString(column));
            if (column.IsIdentity)
            {
                builder.AppendFormat(" Identity({0}, {1})", column.IdentitySeed, column.Increment);
            }
            if (column.IsPrimary || !column.IsNullable)
            {
                builder.Append(" Not");
            }
            builder.Append(" Null");
            if (!string.IsNullOrEmpty(column.DefaultValue))
            {
                builder.AppendFormat(" Constraint [DF_{0}_{1}] Default ({2})", table.Name, column.Name, column.DefaultValue);
            }
            return(builder.ToString());
        }
Example #8
0
        private Type GetColumnMappingType(ISchemaColumn column)
        {
            if (column.ConverterType != null)
            {
                var converter = EntityConverterManager.Gain(column.ConverterType);
                return(converter.GetMappingType(column.PropertyType));
            }
            if (column.PropertyType.IsEnum)
            {
                return(Enum.GetUnderlyingType(column.PropertyType));
            }
            var types = new Type[]
            {
                typeof(bool),
                typeof(byte),
                typeof(sbyte),
                typeof(short),
                typeof(ushort),
                typeof(int),
                typeof(uint),
                typeof(long),
                typeof(ulong),
                typeof(float),
                typeof(double),
                typeof(decimal),
                typeof(DateTime),
                typeof(Guid),
            };

            if (types.Contains(column.PropertyType))
            {
                return(column.PropertyType);
            }

            return(typeof(string));
        }
 private static string CleanDefaultValue(ISchemaColumn column)
 {
     return column.SystemType.LikeAny("string","guid","datetime","bool","long","short","int","double","float","decimal") 
         ? column.DefaultValue.Substring(2).Remove(column.DefaultValue.Length - 4, 2)
         : column.DefaultValue;
 }
        private static string GetDatabaseGeneratedOption(ISchemaColumn column)
        {
            var hasDatabaseGeneratedOption = (column.SystemType.Like("guid")   || column.SystemType.Like("long") ||
                                              column.SystemType.Like("short")  || column.SystemType.Like("int") ||
                                              column.SystemType.Like("double") || column.SystemType.Like("float") ||
                                              column.SystemType.Like("decimal"));

            if (!hasDatabaseGeneratedOption) 
                return string.Empty;

            if (column.IsIdentity)
                return "\r\n\t.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)";

            if (column.IsStoreGenerated)
                return "\r\n\t.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed)";

            if (column.IsPrimaryKey && !column.IsIdentity && !column.IsStoreGenerated)
                return "\r\n\t.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)";

            return string.Empty;
        }
 private static bool HasComputedDefaultValue(ISchemaColumn column)
 {
     return column.DefaultValue.ContainsAny("getdate", "getutcdate", "newid", "newsequentialid");
 }
 private static string CheckNullable(ISchemaColumn column)
 {
     return column.IsNullable && column.SystemType.NotLikeAll(NonNullableTypes) 
         ? "?" 
         : string.Empty;
 }
 public PropertyInfoAdapter(ISchemaColumn column, ISchemaTable table, IIdentifierGenerationService identifierGenerationService)
 {
     this.column               = column;
     this.table                = table;
     this.identifierGenerationService = identifierGenerationService;
 }
Example #14
0
 private ISchemaColumn ConvertColumnToNullable(ISchemaColumn column)
 {
     return(new SchemaColumn(column.ColumnName, column.ColumnIndex, ConvertToNullable(column.ColumnType)));
 }
 public IPropertyInfoAdapter Create(ISchemaColumn column, ISchemaTable table, IIdentifierGenerationService identifierGenerationService)
 {
     return new PropertyInfoAdapter(column, table, identifierGenerationService);
 }