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


C# DocumentMapping.ToTable方法代码示例

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


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

示例1: equivalency_negative_column_type_changed

        public void equivalency_negative_column_type_changed()
        {
            var users = new DocumentMapping(typeof(User));
            var table1 = users.ToTable(null);
            var table2 = users.ToTable(null);

            table2.PrimaryKey.Type = "int";

            table2.ShouldNotBe(table1);
        }
开发者ID:kiliman,项目名称:marten,代码行数:10,代码来源:TableDefinitionTests.cs

示例2: equivalency_negative_different_numbers_of_columns

        public void equivalency_negative_different_numbers_of_columns()
        {
            var users = new DocumentMapping(typeof(User));
            var table1 = users.ToTable(null);
            var table2 = users.ToTable(null);

            table2.Columns.Add(new TableColumn("user_name", "character varying"));

            table2.ShouldNotBe(table1);
        }
开发者ID:kiliman,项目名称:marten,代码行数:10,代码来源:TableDefinitionTests.cs

示例3: equivalency_positive

        public void equivalency_positive()
        {
            var users = new DocumentMapping(typeof(User));
            var table1 = users.ToTable(null);
            var table2 = users.ToTable(null);

            table2.ShouldBe(table1);
            table1.ShouldBe(table2);
            table1.ShouldNotBeSameAs(table2);
        }
开发者ID:kiliman,项目名称:marten,代码行数:10,代码来源:TableDefinitionTests.cs

示例4: SchemaDiff

        public SchemaDiff(IDocumentSchema schema, SchemaObjects existing, DocumentMapping mapping)
        {
            if (existing.HasNone())
            {
                AllMissing = true;
            }
            else
            {
                var expectedTable = mapping.ToTable(schema);
                TableDiff = new TableDiff(expectedTable, existing.Table);

                // TODO -- drop obsolete indices?

                mapping.Indexes.Each(index =>
                {
                    if (existing.ActualIndices.ContainsKey(index.IndexName))
                    {
                        var actualIndex = existing.ActualIndices[index.IndexName];
                        if (!index.Matches(actualIndex))
                        {
                            IndexChanges.Add($"drop index {expectedTable.Table.Schema}.{index.IndexName};{index.ToDDL()}");
                        }
                    }
                    else
                    {
                        IndexChanges.Add(index.ToDDL());
                    }
                });

            }

            _existing = existing;
            _mapping = mapping;
            _schema = schema;
        }
开发者ID:,项目名称:,代码行数:35,代码来源:

示例5: WriteSchemaObjects

        public static void WriteSchemaObjects(DocumentMapping mapping, IDocumentSchema schema, StringWriter writer)
        {
            var table = mapping.ToTable(schema);
            table.Write(writer);
            writer.WriteLine();
            writer.WriteLine();

            var pgIdType = TypeMappings.GetPgType(mapping.IdMember.GetMemberType());

            var args = new List<UpsertArgument>
            {
                new UpsertArgument {Arg = "docId", PostgresType = pgIdType},
                new UpsertArgument {Arg = "doc", PostgresType = "JSON"}
            };

            var duplicates = mapping.DuplicatedFields.Select(x => x.UpsertArgument).ToArray();
            args.AddRange(duplicates);

            var argList = args.Select(x => x.ArgumentDeclaration()).Join(", ");
            var valueList = args.Select(x => x.Arg).Join(", ");

            var updates = "data = doc";
            if (duplicates.Any())
            {
                updates += ", " + duplicates.Select(x => $"{x.Column} = {x.Arg}").Join(", ");
            }

            writer.WriteLine($"CREATE OR REPLACE FUNCTION {mapping.UpsertName}({argList}) RETURNS VOID AS");
            writer.WriteLine("$$");
            writer.WriteLine("BEGIN");
            writer.WriteLine($"INSERT INTO {mapping.TableName} VALUES ({valueList})");
            writer.WriteLine($"  ON CONFLICT ON CONSTRAINT pk_{mapping.TableName}");
            writer.WriteLine($"  DO UPDATE SET {updates};");
            writer.WriteLine("END;");
            writer.WriteLine("$$ LANGUAGE plpgsql;");

            writer.WriteLine();
            writer.WriteLine();
        }
开发者ID:danbarua,项目名称:Marten,代码行数:39,代码来源:SchemaBuilder.cs

示例6: WriteSchemaObjects

        public static void WriteSchemaObjects(DocumentMapping mapping, IDocumentSchema schema, StringWriter writer)
        {
            var table = mapping.ToTable(schema);
            table.Write(writer);
            writer.WriteLine();
            writer.WriteLine();

            var pgIdType = TypeMappings.GetPgType(mapping.IdMember.GetMemberType());

            var args = new List<UpsertArgument>
            {
                new UpsertArgument {Arg = "docId", PostgresType = pgIdType},
                new UpsertArgument {Arg = "doc", PostgresType = "JSONB"}
            };

            var duplicates = mapping.DuplicatedFields.Select(x => x.UpsertArgument).ToArray();
            args.AddRange(duplicates);

            var argList = args.Select(x => x.ArgumentDeclaration()).Join(", ");
            var valueList = args.Select(x => x.Arg).Join(", ");

            var updates = "data = doc";
            if (duplicates.Any())
            {
                updates += ", " + duplicates.Select(x => $"{x.Column} = {x.Arg}").Join(", ");
            }

            if (schema != null && schema.UpsertType == PostgresUpsertType.Legacy)
            {
                var inserts = "id, data";
                if (duplicates.Any())
                {
                    inserts += ", " + duplicates.Select(x => x.Column).Join(", ");
                }
                writer.WriteLine($"CREATE OR REPLACE FUNCTION {mapping.UpsertName}({argList}) RETURNS VOID AS");
                writer.WriteLine("$$");
                writer.WriteLine("BEGIN");
                writer.WriteLine($"LOCK TABLE {mapping.TableName} IN SHARE ROW EXCLUSIVE MODE;");
                writer.WriteLine($"  WITH upsert AS (UPDATE {mapping.TableName} SET {updates} WHERE id=docId RETURNING *) ");
                writer.WriteLine($"  INSERT INTO {mapping.TableName} ({inserts})");
                writer.WriteLine($"  SELECT {valueList} WHERE NOT EXISTS (SELECT * FROM upsert);");
                writer.WriteLine("END;");
                writer.WriteLine("$$ LANGUAGE plpgsql;");
            }
            else
            {
                writer.WriteLine($"CREATE OR REPLACE FUNCTION {mapping.UpsertName}({argList}) RETURNS VOID AS");
                writer.WriteLine("$$");
                writer.WriteLine("BEGIN");
                writer.WriteLine($"INSERT INTO {mapping.TableName} VALUES ({valueList})");
                writer.WriteLine($"  ON CONFLICT ON CONSTRAINT pk_{mapping.TableName}");
                writer.WriteLine($"  DO UPDATE SET {updates};");
                writer.WriteLine("END;");
                writer.WriteLine("$$ LANGUAGE plpgsql;");
            }

            mapping.Indexes.Each(x =>
            {
                writer.WriteLine();
                writer.WriteLine(x.ToDDL());
            });

            writer.WriteLine();
            writer.WriteLine();


        }
开发者ID:kiliman,项目名称:marten,代码行数:67,代码来源:SchemaBuilder.cs


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