当前位置: 首页>>代码示例>>C#>>正文


C# IQueryContext.TypeResolver方法代码示例

本文整理汇总了C#中IQueryContext.TypeResolver方法的典型用法代码示例。如果您正苦于以下问题:C# IQueryContext.TypeResolver方法的具体用法?C# IQueryContext.TypeResolver怎么用?C# IQueryContext.TypeResolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IQueryContext的用法示例。


在下文中一共展示了IQueryContext.TypeResolver方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Build

            public static void Build(IQueryContext context, CreateTableNode node, ICollection<SqlStatement> statements)
            {
                string idColumn = null;

                var dataTypeBuilder = new DataTypeBuilder();

                var tableName = node.TableName;
                var objTableName = ObjectName.Parse(tableName.Name);
                var constraints = new List<ConstraintInfo>();
                var columns = new List<SqlTableColumn>();

                var expBuilder = new ExpressionBuilder();

                foreach (var column in node.Columns) {
                    var dataType = dataTypeBuilder.Build(context.TypeResolver(), column.DataType);

                    var columnInfo = new SqlTableColumn(column.ColumnName.Text, dataType);

                    if (column.Default != null)
                        columnInfo.DefaultExpression = expBuilder.Build(column.Default);

                    if (column.IsIdentity) {
                        if (!String.IsNullOrEmpty(idColumn))
                            throw new InvalidOperationException(String.Format("Table {0} defines already {1} as identity column.",
                                node.TableName, idColumn));

                        if (column.Default != null)
                            throw new InvalidOperationException(String.Format("The identity column {0} cannot have a DEFAULT constraint.",
                                idColumn));

                        idColumn = column.ColumnName.Text;

                        columnInfo.DefaultExpression = SqlExpression.FunctionCall("UNIQUEKEY",
                            new[] {SqlExpression.Constant(node.TableName.Name)});
                    }

                    foreach (var constraint in column.Constraints) {
                        if (String.Equals(ConstraintTypeNames.Check, constraint.ConstraintType, StringComparison.OrdinalIgnoreCase)) {
                            var exp = expBuilder.Build(constraint.CheckExpression);
                            constraints.Add(ConstraintInfo.Check(objTableName, exp, column.ColumnName.Text));
                        } else if (String.Equals(ConstraintTypeNames.ForeignKey, constraint.ConstraintType, StringComparison.OrdinalIgnoreCase)) {
                            var fTable = ObjectName.Parse(constraint.ReferencedTable.Name);
                            var fColumn = constraint.ReferencedColumn.Text;
                            var fkey = ConstraintInfo.ForeignKey(objTableName, column.ColumnName.Text, fTable, fColumn);
                            if (!String.IsNullOrEmpty(constraint.OnDeleteAction))
                                fkey.OnDelete = GetForeignKeyAction(constraint.OnDeleteAction);
                            if (!String.IsNullOrEmpty(constraint.OnUpdateAction))
                                fkey.OnUpdate = GetForeignKeyAction(constraint.OnUpdateAction);

                            constraints.Add(fkey);
                        } else if (String.Equals(ConstraintTypeNames.PrimaryKey, constraint.ConstraintType, StringComparison.OrdinalIgnoreCase)) {
                            constraints.Add(ConstraintInfo.PrimaryKey(objTableName, column.ColumnName.Text));
                        } else if (String.Equals(ConstraintTypeNames.UniqueKey, constraint.ConstraintType, StringComparison.OrdinalIgnoreCase)) {
                            constraints.Add(ConstraintInfo.Unique(objTableName, column.ColumnName.Text));
                        } else if (String.Equals(ConstraintTypeNames.NotNull, constraint.ConstraintType, StringComparison.OrdinalIgnoreCase)) {
                            columnInfo.IsNotNull = true;
                        } else if (String.Equals(ConstraintTypeNames.Null, constraint.ConstraintType, StringComparison.OrdinalIgnoreCase)) {
                            columnInfo.IsNotNull = false;
                        }
                    }

                    columns.Add(columnInfo);
                }

                foreach (var constraint in node.Constraints) {
                    if (String.Equals(ConstraintTypeNames.Check, constraint.ConstraintType, StringComparison.OrdinalIgnoreCase)) {
                        var exp = expBuilder.Build(constraint.CheckExpression);
                        constraints.Add(ConstraintInfo.Check(constraint.ConstraintName, objTableName, exp, constraint.Columns.ToArray()));
                    } else if (String.Equals(ConstraintTypeNames.PrimaryKey, constraint.ConstraintType, StringComparison.OrdinalIgnoreCase)) {
                        constraints.Add(ConstraintInfo.PrimaryKey(constraint.ConstraintName, objTableName, constraint.Columns.ToArray()));
                    } else if (String.Equals(ConstraintTypeNames.UniqueKey, constraint.ConstraintType, StringComparison.OrdinalIgnoreCase)) {
                        constraints.Add(ConstraintInfo.Unique(constraint.ConstraintName, objTableName, constraint.Columns.ToArray()));
                    } else if (String.Equals(ConstraintTypeNames.ForeignKey, constraint.ConstraintType, StringComparison.OrdinalIgnoreCase)) {
                        var fTable = ObjectName.Parse(constraint.ReferencedTableName.Name);
                        var fColumns = constraint.ReferencedColumns;
                        var fkey = ConstraintInfo.ForeignKey(constraint.ConstraintName, objTableName, constraint.Columns.ToArray(), fTable,
                            fColumns.ToArray());
                        if (!String.IsNullOrEmpty(constraint.OnDeleteAction))
                            fkey.OnDelete = GetForeignKeyAction(constraint.OnDeleteAction);
                        if (!String.IsNullOrEmpty(constraint.OnUpdateAction))
                            fkey.OnUpdate = GetForeignKeyAction(constraint.OnUpdateAction);

                        constraints.Add(fkey);
                    }
                }

                //TODO: Optimization: merge same constraints

                statements.Add(MakeCreateTable(tableName.Name, columns, node.IfNotExists, node.Temporary));

                foreach (var constraint in constraints) {
                    statements.Add(MakeAlterTableAddConstraint(tableName.Name, constraint));
                }
            }
开发者ID:prepare,项目名称:deveeldb,代码行数:94,代码来源:StatementBuilder.cs


注:本文中的IQueryContext.TypeResolver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。