コード例 #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);
        }
コード例 #2
0
        private static int GenerateConstraints(this Model model, IndentedStringBuilder sqlBuilder, MySqlVersion mySqlVersion, 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, mySqlVersion, (DbCheckConstraint)constraint);
                }
                else if (constraint is DbForeignKeyConstraint)
                {
                    GenerateForeignKeyConstraint(sqlBuilder, (DbForeignKeyConstraint)constraint);
                }
                else
                {
                    throw new NotSupportedException(DiagnosticMessages.ConstraintTypeNotSupported(constraint.GetType()));
                }
            }
            return(constraints.Count);
        }
コード例 #3
0
ファイル: ColumnExtensions.cs プロジェクト: xydoublez/RDO.Net
        private static MySqlTypeProvider GetDefaultSqlTypeProvider(this Column column)
        {
            MySqlTypeProvider result;

            if (s_defaultMySqlTypeProviders.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_defaultMySqlTypeProviders.GetOrAdd(columnType, BuildSqlTypeProviderFactory(methodInfo, enumType)));
            }

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

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

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

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

            throw new NotSupportedException(DiagnosticMessages.ColumnTypeNotSupported(column.GetType()));
        }