Beispiel #1
0
        /// <inheritdoc/>
        public override void Visit(DbFunctionExpression e)
        {
            Action <ExpressionGenerator, DbFunctionExpression> handler;

            try
            {
                handler = s_functionHandlers[e.FunctionKey];
            }
            catch (KeyNotFoundException)
            {
                throw new NotSupportedException(DiagnosticMessages.FunctionNotSupported(e.FunctionKey));
            }
            handler(this, e);
        }
Beispiel #2
0
        private static int GenerateConstraints(this Model model, IndentedStringBuilder sqlBuilder, SqlVersion sqlVersion, string tableName, bool isTempTable)
        {
            IReadOnlyList <DbTableConstraint> constraints = model.GetAddons <DbTableConstraint>();

            if (isTempTable)
            {
                constraints = constraints.Where(x => x.IsValidOnTempTable).ToList();
            }
            else
            {
                constraints = constraints.Where(x => x.IsValidOnTable).ToList();
            }
            if (constraints.Count == 0)
            {
                return(0);
            }

            sqlBuilder.AppendLine();
            for (int i = 0; i < constraints.Count; i++)
            {
                if (i > 0)
                {
                    sqlBuilder.AppendLine(",");
                }
                var constraint = constraints[i];
                sqlBuilder.GenerateConstraintName(constraint.Name, tableName, isTempTable);
                if (constraint is DbPrimaryKey)
                {
                    GeneratePrimaryKeyConstraint(sqlBuilder, (DbPrimaryKey)constraint);
                }
                else if (constraint is DbUniqueConstraint)
                {
                    GenerateUniqueConstraint(sqlBuilder, (DbUniqueConstraint)constraint);
                }
                else if (constraint is DbCheckConstraint)
                {
                    GenerateCheckConstraint(sqlBuilder, sqlVersion, (DbCheckConstraint)constraint);
                }
                else if (constraint is DbForeignKeyConstraint)
                {
                    GenerateForeignKeyConstraint(sqlBuilder, (DbForeignKeyConstraint)constraint);
                }
                else
                {
                    throw new NotSupportedException(DiagnosticMessages.ConstraintTypeNotSupported(constraint.GetType().FullName));
                }
            }
            return(constraints.Count);
        }
Beispiel #3
0
        private static SqlTypeProvider GetDefaultSqlTypeProvider(this Column column)
        {
            SqlTypeProvider result;

            if (s_defaultSqlTypeProviders.TryGetValue(column.DataType, out result))
            {
                return(result);
            }

            var columnType     = column.GetType();
            var columnDataType = column.DataType;
            var enumType       = columnDataType.GenericTypeArguments[0];

            if (columnType.IsDerivedFromGeneric(typeof(_ByteEnum <>)))
            {
                var methodInfo = typeof(ColumnExtensions).GetStaticMethodInfo(nameof(GetByteEnumColumnDescriptorProvider));
                return(s_defaultSqlTypeProviders.GetOrAdd(columnType, BuildSqlTypeProviderFactory(methodInfo, enumType)));
            }

            if (columnType.IsDerivedFromGeneric(typeof(_CharEnum <>)))
            {
                var methodInfo = typeof(ColumnExtensions).GetStaticMethodInfo(nameof(GetCharEnumColumnDescriptorProvider));
                return(s_defaultSqlTypeProviders.GetOrAdd(columnType, BuildSqlTypeProviderFactory(methodInfo, enumType)));
            }

            if (columnType.IsDerivedFromGeneric(typeof(_Int16Enum <>)))
            {
                var methodInfo = typeof(ColumnExtensions).GetStaticMethodInfo(nameof(GetInt16EnumColumnDescriptorProvider));
                return(s_defaultSqlTypeProviders.GetOrAdd(columnType, BuildSqlTypeProviderFactory(methodInfo, enumType)));
            }

            if (columnType.IsDerivedFromGeneric(typeof(_Int32Enum <>)))
            {
                var methodInfo = typeof(ColumnExtensions).GetStaticMethodInfo(nameof(GetInt32EnumColumnDescriptorProvider));
                return(s_defaultSqlTypeProviders.GetOrAdd(columnType, BuildSqlTypeProviderFactory(methodInfo, enumType)));
            }

            if (columnType.IsDerivedFromGeneric(typeof(_Int64Enum <>)))
            {
                var methodInfo = typeof(ColumnExtensions).GetStaticMethodInfo(nameof(GetInt64EnumColumnDescriptorProvider));
                return(s_defaultSqlTypeProviders.GetOrAdd(columnType, BuildSqlTypeProviderFactory(methodInfo, enumType)));
            }

            throw new NotSupportedException(DiagnosticMessages.ColumnTypeNotSupported(column.GetType()));
        }
Beispiel #4
0
 public void Resources_correctly_embeded()
 {
     Assert.IsNotNull(DiagnosticMessages.ColumnTypeNotSupported(typeof(_String)));
 }