diff --git a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationOperationGeneratorTest.cs b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationOperationGeneratorTest.cs index 9bae3036bc4..a7e5224d1dd 100644 --- a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationOperationGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationOperationGeneratorTest.cs @@ -11,8 +11,6 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Design; public class CSharpMigrationOperationGeneratorTest { - private static readonly string _eol = Environment.NewLine; - [ConditionalFact] public void Generate_separates_operations_by_a_blank_line() { @@ -31,8 +29,12 @@ public void Generate_separates_operations_by_a_blank_line() builder); Assert.Equal( - "mb.Sql(\"-- Don't stand so\");" + _eol + _eol + "mb.Sql(\"-- close to me\");", - builder.ToString()); +""" +mb.Sql("-- Don't stand so"); + +mb.Sql("-- close to me"); +""", + builder.ToString(), ignoreLineEndingDifferences: true); } [ConditionalFact] @@ -44,7 +46,12 @@ public void AddColumnOperation_required_args() Table = "Post", ClrType = typeof(int) }, - "mb.AddColumn(" + _eol + " name: \"Id\"," + _eol + " table: \"Post\"," + _eol + " nullable: false);", +""" +mb.AddColumn( + name: "Id", + table: "Post", + nullable: false); +""", o => { Assert.Equal("Id", o.Name); @@ -73,35 +80,23 @@ public void AddColumnOperation_all_args() Comment = "My Comment", Collation = "Some Collation" }, - "mb.AddColumn(" - + _eol - + " name: \"Id\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"Post\"," - + _eol - + " type: \"int\"," - + _eol - + " unicode: false," - + _eol - + " fixedLength: true," - + _eol - + " maxLength: 30," - + _eol - + " precision: 10," - + _eol - + " scale: 5," - + _eol - + " rowVersion: true," - + _eol - + " nullable: true," - + _eol - + " defaultValue: 1," - + _eol - + " comment: \"My Comment\"," - + _eol - + " collation: \"Some Collation\");", +""" +mb.AddColumn( + name: "Id", + schema: "dbo", + table: "Post", + type: "int", + unicode: false, + fixedLength: true, + maxLength: 30, + precision: 10, + scale: 5, + rowVersion: true, + nullable: true, + defaultValue: 1, + comment: "My Comment", + collation: "Some Collation"); +""", o => { Assert.Equal("Id", o.Name); @@ -127,15 +122,13 @@ public void AddColumnOperation_DefaultValueSql() ClrType = typeof(int), DefaultValueSql = "1" }, - "mb.AddColumn(" - + _eol - + " name: \"Id\"," - + _eol - + " table: \"Post\"," - + _eol - + " nullable: false," - + _eol - + " defaultValueSql: \"1\");", +""" +mb.AddColumn( + name: "Id", + table: "Post", + nullable: false, + defaultValueSql: "1"); +""", o => { Assert.Equal("Id", o.Name); @@ -155,17 +148,14 @@ public void AddColumnOperation_ComputedExpression() ComputedColumnSql = "1", IsStored = true }, - "mb.AddColumn(" - + _eol - + " name: \"Id\"," - + _eol - + " table: \"Post\"," - + _eol - + " nullable: false," - + _eol - + " computedColumnSql: \"1\"," - + _eol - + " stored: true);", +""" +mb.AddColumn( + name: "Id", + table: "Post", + nullable: false, + computedColumnSql: "1", + stored: true); +""", o => { Assert.Equal("Id", o.Name); @@ -185,15 +175,13 @@ public void AddForeignKeyOperation_required_args() Columns = new[] { "BlogId" }, PrincipalTable = "Blog" }, - "mb.AddForeignKey(" - + _eol - + " name: \"FK_Post_Blog_BlogId\"," - + _eol - + " table: \"Post\"," - + _eol - + " column: \"BlogId\"," - + _eol - + " principalTable: \"Blog\");", +""" +mb.AddForeignKey( + name: "FK_Post_Blog_BlogId", + table: "Post", + column: "BlogId", + principalTable: "Blog"); +""", o => { Assert.Equal("FK_Post_Blog_BlogId", o.Name); @@ -213,15 +201,13 @@ public void AddForeignKeyOperation_required_args_composite() Columns = new[] { "BlogId1", "BlogId2" }, PrincipalTable = "Blog" }, - "mb.AddForeignKey(" - + _eol - + " name: \"FK_Post_Blog_BlogId1_BlogId2\"," - + _eol - + " table: \"Post\"," - + _eol - + " columns: new[] { \"BlogId1\", \"BlogId2\" }," - + _eol - + " principalTable: \"Blog\");", +""" +mb.AddForeignKey( + name: "FK_Post_Blog_BlogId1_BlogId2", + table: "Post", + columns: new[] { "BlogId1", "BlogId2" }, + principalTable: "Blog"); +""", o => { Assert.Equal("FK_Post_Blog_BlogId1_BlogId2", o.Name); @@ -246,25 +232,18 @@ public void AddForeignKeyOperation_all_args() OnUpdate = ReferentialAction.Restrict, OnDelete = ReferentialAction.Cascade }, - "mb.AddForeignKey(" - + _eol - + " name: \"FK_Post_Blog_BlogId\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"Post\"," - + _eol - + " column: \"BlogId\"," - + _eol - + " principalSchema: \"my\"," - + _eol - + " principalTable: \"Blog\"," - + _eol - + " principalColumn: \"Id\"," - + _eol - + " onUpdate: ReferentialAction.Restrict," - + _eol - + " onDelete: ReferentialAction.Cascade);", +""" +mb.AddForeignKey( + name: "FK_Post_Blog_BlogId", + schema: "dbo", + table: "Post", + column: "BlogId", + principalSchema: "my", + principalTable: "Blog", + principalColumn: "Id", + onUpdate: ReferentialAction.Restrict, + onDelete: ReferentialAction.Cascade); +""", o => { Assert.Equal("FK_Post_Blog_BlogId", o.Name); @@ -293,25 +272,18 @@ public void AddForeignKeyOperation_all_args_composite() OnUpdate = ReferentialAction.Restrict, OnDelete = ReferentialAction.Cascade }, - "mb.AddForeignKey(" - + _eol - + " name: \"FK_Post_Blog_BlogId1_BlogId2\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"Post\"," - + _eol - + " columns: new[] { \"BlogId1\", \"BlogId2\" }," - + _eol - + " principalSchema: \"my\"," - + _eol - + " principalTable: \"Blog\"," - + _eol - + " principalColumns: new[] { \"Id1\", \"Id2\" }," - + _eol - + " onUpdate: ReferentialAction.Restrict," - + _eol - + " onDelete: ReferentialAction.Cascade);", +""" +mb.AddForeignKey( + name: "FK_Post_Blog_BlogId1_BlogId2", + schema: "dbo", + table: "Post", + columns: new[] { "BlogId1", "BlogId2" }, + principalSchema: "my", + principalTable: "Blog", + principalColumns: new[] { "Id1", "Id2" }, + onUpdate: ReferentialAction.Restrict, + onDelete: ReferentialAction.Cascade); +""", o => { Assert.Equal("FK_Post_Blog_BlogId1_BlogId2", o.Name); @@ -334,7 +306,12 @@ public void AddPrimaryKey_required_args() Table = "Post", Columns = new[] { "Id" } }, - "mb.AddPrimaryKey(" + _eol + " name: \"PK_Post\"," + _eol + " table: \"Post\"," + _eol + " column: \"Id\");", +""" +mb.AddPrimaryKey( + name: "PK_Post", + table: "Post", + column: "Id"); +""", o => { Assert.Equal("PK_Post", o.Name); @@ -352,15 +329,13 @@ public void AddPrimaryKey_all_args() Table = "Post", Columns = new[] { "Id" } }, - "mb.AddPrimaryKey(" - + _eol - + " name: \"PK_Post\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"Post\"," - + _eol - + " column: \"Id\");", +""" +mb.AddPrimaryKey( + name: "PK_Post", + schema: "dbo", + table: "Post", + column: "Id"); +""", o => { Assert.Equal("PK_Post", o.Name); @@ -378,13 +353,12 @@ public void AddPrimaryKey_composite() Table = "Post", Columns = new[] { "Id1", "Id2" } }, - "mb.AddPrimaryKey(" - + _eol - + " name: \"PK_Post\"," - + _eol - + " table: \"Post\"," - + _eol - + " columns: new[] { \"Id1\", \"Id2\" });", +""" +mb.AddPrimaryKey( + name: "PK_Post", + table: "Post", + columns: new[] { "Id1", "Id2" }); +""", o => { Assert.Equal("PK_Post", o.Name); @@ -401,13 +375,12 @@ public void AddUniqueConstraint_required_args() Table = "Post", Columns = new[] { "AltId" } }, - "mb.AddUniqueConstraint(" - + _eol - + " name: \"AK_Post_AltId\"," - + _eol - + " table: \"Post\"," - + _eol - + " column: \"AltId\");", +""" +mb.AddUniqueConstraint( + name: "AK_Post_AltId", + table: "Post", + column: "AltId"); +""", o => { Assert.Equal("AK_Post_AltId", o.Name); @@ -425,15 +398,13 @@ public void AddUniqueConstraint_all_args() Table = "Post", Columns = new[] { "AltId" } }, - "mb.AddUniqueConstraint(" - + _eol - + " name: \"AK_Post_AltId\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"Post\"," - + _eol - + " column: \"AltId\");", +""" +mb.AddUniqueConstraint( + name: "AK_Post_AltId", + schema: "dbo", + table: "Post", + column: "AltId"); +""", o => { Assert.Equal("AK_Post_AltId", o.Name); @@ -451,13 +422,12 @@ public void AddUniqueConstraint_composite() Table = "Post", Columns = new[] { "AltId1", "AltId2" } }, - "mb.AddUniqueConstraint(" - + _eol - + " name: \"AK_Post_AltId1_AltId2\"," - + _eol - + " table: \"Post\"," - + _eol - + " columns: new[] { \"AltId1\", \"AltId2\" });", +""" +mb.AddUniqueConstraint( + name: "AK_Post_AltId1_AltId2", + table: "Post", + columns: new[] { "AltId1", "AltId2" }); +""", o => { Assert.Equal("AK_Post_AltId1_AltId2", o.Name); @@ -474,13 +444,12 @@ public void AddCheckConstraint_required_args() Table = "Post", Sql = "AltId1 > AltId2" }, - "mb.AddCheckConstraint(" - + _eol - + " name: \"CK_Post_AltId1_AltId2\"," - + _eol - + " table: \"Post\"," - + _eol - + " sql: \"AltId1 > AltId2\");", +""" +mb.AddCheckConstraint( + name: "CK_Post_AltId1_AltId2", + table: "Post", + sql: "AltId1 > AltId2"); +""", o => { Assert.Equal("CK_Post_AltId1_AltId2", o.Name); @@ -498,15 +467,13 @@ public void AddCheckConstraint_all_args() Table = "Post", Sql = "AltId1 > AltId2" }, - "mb.AddCheckConstraint(" - + _eol - + " name: \"CK_Post_AltId1_AltId2\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"Post\"," - + _eol - + " sql: \"AltId1 > AltId2\");", +""" +mb.AddCheckConstraint( + name: "CK_Post_AltId1_AltId2", + schema: "dbo", + table: "Post", + sql: "AltId1 > AltId2"); +""", o => { Assert.Equal("CK_Post_AltId1_AltId2", o.Name); @@ -524,7 +491,12 @@ public void AlterColumnOperation_required_args() Table = "Post", ClrType = typeof(int) }, - "mb.AlterColumn(" + _eol + " name: \"Id\"," + _eol + " table: \"Post\"," + _eol + " nullable: false);", +""" +mb.AlterColumn( + name: "Id", + table: "Post", + nullable: false); +""", o => { Assert.Equal("Id", o.Name); @@ -595,59 +567,35 @@ public void AlterColumnOperation_all_args() Collation = "Some Collation" } }, - "mb.AlterColumn(" - + _eol - + " name: \"Id\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"Post\"," - + _eol - + " type: \"int\"," - + _eol - + " unicode: false," - + _eol - + " fixedLength: true," - + _eol - + " maxLength: 30," - + _eol - + " precision: 10," - + _eol - + " scale: 5," - + _eol - + " rowVersion: true," - + _eol - + " nullable: true," - + _eol - + " defaultValue: 1," - + _eol - + " comment: \"My Comment 2\"," - + _eol - + " collation: \"Some Collation 2\"," - + _eol - + " oldClrType: typeof(string)," - + _eol - + " oldType: \"string\"," - + _eol - + " oldUnicode: false," - + _eol - + " oldFixedLength: true," - + _eol - + " oldMaxLength: 20," - + _eol - + " oldPrecision: 5," - + _eol - + " oldScale: 1," - + _eol - + " oldRowVersion: true," - + _eol - + " oldNullable: true," - + _eol - + " oldDefaultValue: 0," - + _eol - + " oldComment: \"My Comment\"," - + _eol - + " oldCollation: \"Some Collation\");", +""" +mb.AlterColumn( + name: "Id", + schema: "dbo", + table: "Post", + type: "int", + unicode: false, + fixedLength: true, + maxLength: 30, + precision: 10, + scale: 5, + rowVersion: true, + nullable: true, + defaultValue: 1, + comment: "My Comment 2", + collation: "Some Collation 2", + oldClrType: typeof(string), + oldType: "string", + oldUnicode: false, + oldFixedLength: true, + oldMaxLength: 20, + oldPrecision: 5, + oldScale: 1, + oldRowVersion: true, + oldNullable: true, + oldDefaultValue: 0, + oldComment: "My Comment", + oldCollation: "Some Collation"); +""", o => { Assert.Equal("Id", o.Name); @@ -693,15 +641,13 @@ public void AlterColumnOperation_DefaultValueSql() ClrType = typeof(int), DefaultValueSql = "1" }, - "mb.AlterColumn(" - + _eol - + " name: \"Id\"," - + _eol - + " table: \"Post\"," - + _eol - + " nullable: false," - + _eol - + " defaultValueSql: \"1\");", +""" +mb.AlterColumn( + name: "Id", + table: "Post", + nullable: false, + defaultValueSql: "1"); +""", o => { Assert.Equal("Id", o.Name); @@ -739,17 +685,14 @@ public void AlterColumnOperation_computedColumnSql() ComputedColumnSql = "1", IsStored = true }, - "mb.AlterColumn(" - + _eol - + " name: \"Id\"," - + _eol - + " table: \"Post\"," - + _eol - + " nullable: false," - + _eol - + " computedColumnSql: \"1\"," - + _eol - + " stored: true);", +""" +mb.AlterColumn( + name: "Id", + table: "Post", + nullable: false, + computedColumnSql: "1", + stored: true); +""", o => { Assert.Equal("Id", o.Name); @@ -789,15 +732,13 @@ public void AlterDatabaseOperation() ["foo"] = "bar", OldDatabase = { Collation = "Some other collation", ["bar"] = "foo" } }, - "mb.AlterDatabase(" - + _eol - + " collation: \"Some collation\"," - + _eol - + " oldCollation: \"Some other collation\")" - + _eol - + " .Annotation(\"foo\", \"bar\")" - + _eol - + " .OldAnnotation(\"bar\", \"foo\");", +""" +mb.AlterDatabase( + collation: "Some collation", + oldCollation: "Some other collation") + .Annotation("foo", "bar") + .OldAnnotation("bar", "foo"); +""", o => { Assert.Equal("Some collation", o.Collation); @@ -810,9 +751,10 @@ public void AlterDatabaseOperation() public void AlterDatabaseOperation_with_default_old_collation() => Test( new AlterDatabaseOperation { Collation = "Some collation" }, - "mb.AlterDatabase(" - + _eol - + " collation: \"Some collation\");", +""" +mb.AlterDatabase( + collation: "Some collation"); +""", o => { Assert.Equal("Some collation", o.Collation); @@ -823,9 +765,10 @@ public void AlterDatabaseOperation_with_default_old_collation() public void AlterDatabaseOperation_with_default_new_collation() => Test( new AlterDatabaseOperation { OldDatabase = { Collation = "Some collation" } }, - "mb.AlterDatabase(" - + _eol - + " oldCollation: \"Some collation\");", +""" +mb.AlterDatabase( + oldCollation: "Some collation"); +""", o => { Assert.Null(o.Collation); @@ -836,7 +779,10 @@ public void AlterDatabaseOperation_with_default_new_collation() public void AlterSequenceOperation_required_args() => Test( new AlterSequenceOperation { Name = "EntityFrameworkHiLoSequence" }, - "mb.AlterSequence(" + _eol + " name: \"EntityFrameworkHiLoSequence\");", +""" +mb.AlterSequence( + name: "EntityFrameworkHiLoSequence"); +""", o => { Assert.Equal("EntityFrameworkHiLoSequence", o.Name); @@ -870,27 +816,19 @@ public void AlterSequenceOperation_all_args() IsCyclic = true } }, - "mb.AlterSequence(" - + _eol - + " name: \"EntityFrameworkHiLoSequence\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " incrementBy: 3," - + _eol - + " minValue: 2L," - + _eol - + " maxValue: 4L," - + _eol - + " cyclic: true," - + _eol - + " oldIncrementBy: 4," - + _eol - + " oldMinValue: 3L," - + _eol - + " oldMaxValue: 5L," - + _eol - + " oldCyclic: true);", +""" +mb.AlterSequence( + name: "EntityFrameworkHiLoSequence", + schema: "dbo", + incrementBy: 3, + minValue: 2L, + maxValue: 4L, + cyclic: true, + oldIncrementBy: 4, + oldMinValue: 3L, + oldMaxValue: 5L, + oldCyclic: true); +""", o => { Assert.Equal("EntityFrameworkHiLoSequence", o.Name); @@ -909,7 +847,10 @@ public void AlterSequenceOperation_all_args() public void AlterTableOperation_required_args() => Test( new AlterTableOperation { Name = "Customer" }, - "mb.AlterTable(" + _eol + " name: \"Customer\");", +""" +mb.AlterTable( + name: "Customer"); +""", o => { Assert.Equal("Customer", o.Name); @@ -925,15 +866,13 @@ public void AlterTableOperation_all_args() Comment = "My Comment 2", OldTable = { Comment = "My Comment" } }, - "mb.AlterTable(" - + _eol - + " name: \"Customer\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " comment: \"My Comment 2\"," - + _eol - + " oldComment: \"My Comment\");", +""" +mb.AlterTable( + name: "Customer", + schema: "dbo", + comment: "My Comment 2", + oldComment: "My Comment"); +""", o => { Assert.Equal("Customer", o.Name); @@ -951,13 +890,12 @@ public void CreateIndexOperation_required_args() Table = "Post", Columns = new[] { "Title" } }, - "mb.CreateIndex(" - + _eol - + " name: \"IX_Post_Title\"," - + _eol - + " table: \"Post\"," - + _eol - + " column: \"Title\");", +""" +mb.CreateIndex( + name: "IX_Post_Title", + table: "Post", + column: "Title"); +""", o => { Assert.Equal("IX_Post_Title", o.Name); @@ -981,21 +919,16 @@ public void CreateIndexOperation_all_args() IsDescending = new[] { true, false }, Filter = "[Title] IS NOT NULL" }, - "mb.CreateIndex(" - + _eol - + " name: \"IX_Post_Title\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"Post\"," - + _eol - + " columns: new[] { \"Title\", \"Name\" }," - + _eol - + " unique: true," - + _eol - + " descending: new[] { true, false }," - + _eol - + " filter: \"[Title] IS NOT NULL\");", +""" +mb.CreateIndex( + name: "IX_Post_Title", + schema: "dbo", + table: "Post", + columns: new[] { "Title", "Name" }, + unique: true, + descending: new[] { true, false }, + filter: "[Title] IS NOT NULL"); +""", o => { Assert.Equal("IX_Post_Title", o.Name); @@ -1016,13 +949,12 @@ public void CreateIndexOperation_composite() Table = "Post", Columns = new[] { "Title", "Subtitle" } }, - "mb.CreateIndex(" - + _eol - + " name: \"IX_Post_Title_Subtitle\"," - + _eol - + " table: \"Post\"," - + _eol - + " columns: new[] { \"Title\", \"Subtitle\" });", +""" +mb.CreateIndex( + name: "IX_Post_Title_Subtitle", + table: "Post", + columns: new[] { "Title", "Subtitle" }); +""", o => { Assert.Equal("IX_Post_Title_Subtitle", o.Name); @@ -1034,14 +966,20 @@ public void CreateIndexOperation_composite() public void CreateSchemaOperation_required_args() => Test( new EnsureSchemaOperation { Name = "my" }, - "mb.EnsureSchema(" + _eol + " name: \"my\");", +""" +mb.EnsureSchema( + name: "my"); +""", o => Assert.Equal("my", o.Name)); [ConditionalFact] public void CreateSequenceOperation_required_args() => Test( new CreateSequenceOperation { Name = "EntityFrameworkHiLoSequence", ClrType = typeof(long) }, - "mb.CreateSequence(" + _eol + " name: \"EntityFrameworkHiLoSequence\");", +""" +mb.CreateSequence( + name: "EntityFrameworkHiLoSequence"); +""", o => { Assert.Equal("EntityFrameworkHiLoSequence", o.Name); @@ -1052,7 +990,10 @@ public void CreateSequenceOperation_required_args() public void CreateSequenceOperation_required_args_not_long() => Test( new CreateSequenceOperation { Name = "EntityFrameworkHiLoSequence", ClrType = typeof(int) }, - "mb.CreateSequence(" + _eol + " name: \"EntityFrameworkHiLoSequence\");", +""" +mb.CreateSequence( + name: "EntityFrameworkHiLoSequence"); +""", o => { Assert.Equal("EntityFrameworkHiLoSequence", o.Name); @@ -1073,21 +1014,16 @@ public void CreateSequenceOperation_all_args() MaxValue = 4, IsCyclic = true }, - "mb.CreateSequence(" - + _eol - + " name: \"EntityFrameworkHiLoSequence\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " startValue: 3L," - + _eol - + " incrementBy: 5," - + _eol - + " minValue: 2L," - + _eol - + " maxValue: 4L," - + _eol - + " cyclic: true);", +""" +mb.CreateSequence( + name: "EntityFrameworkHiLoSequence", + schema: "dbo", + startValue: 3L, + incrementBy: 5, + minValue: 2L, + maxValue: 4L, + cyclic: true); +""", o => { Assert.Equal("EntityFrameworkHiLoSequence", o.Name); @@ -1114,21 +1050,16 @@ public void CreateSequenceOperation_all_args_not_long() MaxValue = 4, IsCyclic = true }, - "mb.CreateSequence(" - + _eol - + " name: \"EntityFrameworkHiLoSequence\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " startValue: 3L," - + _eol - + " incrementBy: 5," - + _eol - + " minValue: 2L," - + _eol - + " maxValue: 4L," - + _eol - + " cyclic: true);", +""" +mb.CreateSequence( + name: "EntityFrameworkHiLoSequence", + schema: "dbo", + startValue: 3L, + incrementBy: 5, + minValue: 2L, + maxValue: 4L, + cyclic: true); +""", o => { Assert.Equal("EntityFrameworkHiLoSequence", o.Name); @@ -1157,23 +1088,17 @@ public void CreateTableOperation_Columns_required_args() } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " Id = table.Column(nullable: false)" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + columns: table => new + { + Id = table.Column(nullable: false) + }, + constraints: table => + { + }); +""", o => { Assert.Equal("Post", o.Name); @@ -1213,25 +1138,18 @@ public void CreateTableOperation_Columns_all_args() } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " PostId = table.Column(name: \"Post Id\", type: \"int\", unicode: false, fixedLength: true, maxLength: 30, precision: 20, scale: 10, rowVersion: true, nullable: true, defaultValue: 1, comment: \"My Comment\", collation: \"Some Collation\")" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + schema: "dbo", + columns: table => new + { + PostId = table.Column(name: "Post Id", type: "int", unicode: false, fixedLength: true, maxLength: 30, precision: 20, scale: 10, rowVersion: true, nullable: true, defaultValue: 1, comment: "My Comment", collation: "Some Collation") + }, + constraints: table => + { + }); +""", o => { Assert.Equal("Post", o.Name); @@ -1268,23 +1186,17 @@ public void CreateTableOperation_Columns_DefaultValueSql() } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " Id = table.Column(nullable: false, defaultValueSql: \"1\")" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + columns: table => new + { + Id = table.Column(nullable: false, defaultValueSql: "1") + }, + constraints: table => + { + }); +""", o => { Assert.Single(o.Columns); @@ -1313,23 +1225,17 @@ public void CreateTableOperation_Columns_computedColumnSql() } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " Id = table.Column(nullable: false, computedColumnSql: \"1\", stored: true)" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + columns: table => new + { + Id = table.Column(nullable: false, computedColumnSql: "1", stored: true) + }, + constraints: table => + { + }); +""", o => { Assert.Single(o.Columns); @@ -1359,31 +1265,21 @@ public void CreateTableOperation_ForeignKeys_required_args() } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " BlogId = table.Column(nullable: false)" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " table.ForeignKey(" - + _eol - + " name: \"FK_Post_Blog_BlogId\"," - + _eol - + " column: x => x.BlogId," - + _eol - + " principalTable: \"Blog\");" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + columns: table => new + { + BlogId = table.Column(nullable: false) + }, + constraints: table => + { + table.ForeignKey( + name: "FK_Post_Blog_BlogId", + column: x => x.BlogId, + principalTable: "Blog"); + }); +""", o => { Assert.Single(o.ForeignKeys); @@ -1419,41 +1315,26 @@ public void CreateTableOperation_ForeignKeys_all_args() } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " BlogId = table.Column(nullable: false)" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " table.ForeignKey(" - + _eol - + " name: \"FK_Post_Blog_BlogId\"," - + _eol - + " column: x => x.BlogId," - + _eol - + " principalSchema: \"my\"," - + _eol - + " principalTable: \"Blog\"," - + _eol - + " principalColumn: \"Id\"," - + _eol - + " onUpdate: ReferentialAction.SetNull," - + _eol - + " onDelete: ReferentialAction.SetDefault);" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + schema: "dbo", + columns: table => new + { + BlogId = table.Column(nullable: false) + }, + constraints: table => + { + table.ForeignKey( + name: "FK_Post_Blog_BlogId", + column: x => x.BlogId, + principalSchema: "my", + principalTable: "Blog", + principalColumn: "Id", + onUpdate: ReferentialAction.SetNull, + onDelete: ReferentialAction.SetDefault); + }); +""", o => { Assert.Single(o.ForeignKeys); @@ -1493,35 +1374,23 @@ public void CreateTableOperation_ForeignKeys_composite() } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " BlogId1 = table.Column(nullable: false)," - + _eol - + " BlogId2 = table.Column(nullable: false)" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " table.ForeignKey(" - + _eol - + " name: \"FK_Post_Blog_BlogId1_BlogId2\"," - + _eol - + " columns: x => new { x.BlogId1, x.BlogId2 }," - + _eol - + " principalTable: \"Blog\"," - + _eol - + " principalColumns: new[] { \"Id1\", \"Id2\" });" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + columns: table => new + { + BlogId1 = table.Column(nullable: false), + BlogId2 = table.Column(nullable: false) + }, + constraints: table => + { + table.ForeignKey( + name: "FK_Post_Blog_BlogId1_BlogId2", + columns: x => new { x.BlogId1, x.BlogId2 }, + principalTable: "Blog", + principalColumns: new[] { "Id1", "Id2" }); + }); +""", o => { Assert.Single(o.ForeignKeys); @@ -1555,33 +1424,22 @@ public void CreateTableOperation_ForeignKeys_composite_no_principal_columns() } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " BlogId1 = table.Column(nullable: false)," - + _eol - + " BlogId2 = table.Column(nullable: false)" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " table.ForeignKey(" - + _eol - + " name: \"FK_Post_Blog_BlogId1_BlogId2\"," - + _eol - + " column: x => new { x.BlogId1, x.BlogId2 }," - + _eol - + " principalTable: \"Blog\");" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + columns: table => new + { + BlogId1 = table.Column(nullable: false), + BlogId2 = table.Column(nullable: false) + }, + constraints: table => + { + table.ForeignKey( + name: "FK_Post_Blog_BlogId1_BlogId2", + column: x => new { x.BlogId1, x.BlogId2 }, + principalTable: "Blog"); + }); +""", o => { Assert.Single(o.ForeignKeys); @@ -1606,25 +1464,18 @@ public void CreateTableOperation_PrimaryKey_required_args() Columns = new[] { "Id" } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " Id = table.Column(nullable: false)" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " table.PrimaryKey(\"PK_Post\", x => x.Id);" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + columns: table => new + { + Id = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Post", x => x.Id); + }); +""", o => { Assert.NotNull(o.PrimaryKey); @@ -1650,27 +1501,19 @@ public void CreateTableOperation_PrimaryKey_all_args() Columns = new[] { "Id" } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " Id = table.Column(nullable: false)" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " table.PrimaryKey(\"PK_Post\", x => x.Id);" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + schema: "dbo", + columns: table => new + { + Id = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Post", x => x.Id); + }); +""", o => { Assert.NotNull(o.PrimaryKey); @@ -1699,27 +1542,19 @@ public void CreateTableOperation_PrimaryKey_composite() Columns = new[] { "Id1", "Id2" } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " Id1 = table.Column(nullable: false)," - + _eol - + " Id2 = table.Column(nullable: false)" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " table.PrimaryKey(\"PK_Post\", x => new { x.Id1, x.Id2 });" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + columns: table => new + { + Id1 = table.Column(nullable: false), + Id2 = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Post", x => new { x.Id1, x.Id2 }); + }); +""", o => { Assert.NotNull(o.PrimaryKey); @@ -1746,25 +1581,18 @@ public void CreateTableOperation_UniqueConstraints_required_args() } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " AltId = table.Column(nullable: false)" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " table.UniqueConstraint(\"AK_Post_AltId\", x => x.AltId);" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + columns: table => new + { + AltId = table.Column(nullable: false) + }, + constraints: table => + { + table.UniqueConstraint("AK_Post_AltId", x => x.AltId); + }); +""", o => { Assert.Single(o.UniqueConstraints); @@ -1793,27 +1621,19 @@ public void CreateTableOperation_UniqueConstraints_all_args() } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " AltId = table.Column(nullable: false)" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " table.UniqueConstraint(\"AK_Post_AltId\", x => x.AltId);" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + schema: "dbo", + columns: table => new + { + AltId = table.Column(nullable: false) + }, + constraints: table => + { + table.UniqueConstraint("AK_Post_AltId", x => x.AltId); + }); +""", o => { Assert.Single(o.UniqueConstraints); @@ -1845,27 +1665,19 @@ public void CreateTableOperation_UniqueConstraints_composite() } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " AltId1 = table.Column(nullable: false)," - + _eol - + " AltId2 = table.Column(nullable: false)" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " table.UniqueConstraint(\"AK_Post_AltId1_AltId2\", x => new { x.AltId1, x.AltId2 });" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + columns: table => new + { + AltId1 = table.Column(nullable: false), + AltId2 = table.Column(nullable: false) + }, + constraints: table => + { + table.UniqueConstraint("AK_Post_AltId1_AltId2", x => new { x.AltId1, x.AltId2 }); + }); +""", o => { Assert.Single(o.UniqueConstraints); @@ -1896,27 +1708,19 @@ public void CreateTableOperation_CheckConstraints_required_args() } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " AltId1 = table.Column(nullable: false)," - + _eol - + " AltId2 = table.Column(nullable: false)" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " table.CheckConstraint(\"CK_Post_AltId1_AltId2\", \"AltId1 > AltId2\");" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + columns: table => new + { + AltId1 = table.Column(nullable: false), + AltId2 = table.Column(nullable: false) + }, + constraints: table => + { + table.CheckConstraint("CK_Post_AltId1_AltId2", "AltId1 > AltId2"); + }); +""", o => { Assert.Single(o.CheckConstraints); @@ -1949,29 +1753,20 @@ public void CreateTableOperation_ChecksConstraints_all_args() } } }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " AltId1 = table.Column(nullable: false)," - + _eol - + " AltId2 = table.Column(nullable: false)" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " table.CheckConstraint(\"CK_Post_AltId1_AltId2\", \"AltId1 > AltId2\");" - + _eol - + " });", +""" +mb.CreateTable( + name: "Post", + schema: "dbo", + columns: table => new + { + AltId1 = table.Column(nullable: false), + AltId2 = table.Column(nullable: false) + }, + constraints: table => + { + table.CheckConstraint("CK_Post_AltId1_AltId2", "AltId1 > AltId2"); + }); +""", o => { Assert.Single(o.CheckConstraints); @@ -1992,27 +1787,19 @@ public void CreateTableOperation_Comment() Columns = { new AddColumnOperation { Name = "AltId1", ClrType = typeof(int) } }, Comment = "My Comment" }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " AltId1 = table.Column(nullable: false)" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " }," - + _eol - + " comment: \"My Comment\");", +""" +mb.CreateTable( + name: "Post", + schema: "dbo", + columns: table => new + { + AltId1 = table.Column(nullable: false) + }, + constraints: table => + { + }, + comment: "My Comment"); +""", o => { Assert.Equal("My Comment", o.Comment); @@ -2036,27 +1823,19 @@ public void CreateTableOperation_TableComment_ColumnComment() }, Comment = "My Operation Comment" }, - "mb.CreateTable(" - + _eol - + " name: \"Post\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " columns: table => new" - + _eol - + " {" - + _eol - + " AltId1 = table.Column(nullable: false, comment: \"My Column comment\")" - + _eol - + " }," - + _eol - + " constraints: table =>" - + _eol - + " {" - + _eol - + " }," - + _eol - + " comment: \"My Operation Comment\");", +""" +mb.CreateTable( + name: "Post", + schema: "dbo", + columns: table => new + { + AltId1 = table.Column(nullable: false, comment: "My Column comment") + }, + constraints: table => + { + }, + comment: "My Operation Comment"); +""", o => { Assert.Equal("My Operation Comment", o.Comment); @@ -2067,7 +1846,11 @@ public void CreateTableOperation_TableComment_ColumnComment() public void DropColumnOperation_required_args() => Test( new DropColumnOperation { Name = "Id", Table = "Post" }, - "mb.DropColumn(" + _eol + " name: \"Id\"," + _eol + " table: \"Post\");", +""" +mb.DropColumn( + name: "Id", + table: "Post"); +""", o => { Assert.Equal("Id", o.Name); @@ -2083,7 +1866,12 @@ public void DropColumnOperation_all_args() Schema = "dbo", Table = "Post" }, - "mb.DropColumn(" + _eol + " name: \"Id\"," + _eol + " schema: \"dbo\"," + _eol + " table: \"Post\");", +""" +mb.DropColumn( + name: "Id", + schema: "dbo", + table: "Post"); +""", o => { Assert.Equal("Id", o.Name); @@ -2095,7 +1883,11 @@ public void DropColumnOperation_all_args() public void DropForeignKeyOperation_required_args() => Test( new DropForeignKeyOperation { Name = "FK_Post_BlogId", Table = "Post" }, - "mb.DropForeignKey(" + _eol + " name: \"FK_Post_BlogId\"," + _eol + " table: \"Post\");", +""" +mb.DropForeignKey( + name: "FK_Post_BlogId", + table: "Post"); +""", o => { Assert.Equal("FK_Post_BlogId", o.Name); @@ -2111,13 +1903,12 @@ public void DropForeignKeyOperation_all_args() Schema = "dbo", Table = "Post" }, - "mb.DropForeignKey(" - + _eol - + " name: \"FK_Post_BlogId\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"Post\");", +""" +mb.DropForeignKey( + name: "FK_Post_BlogId", + schema: "dbo", + table: "Post"); +""", o => { Assert.Equal("FK_Post_BlogId", o.Name); @@ -2129,7 +1920,10 @@ public void DropForeignKeyOperation_all_args() public void DropIndexOperation_required_args() => Test( new DropIndexOperation { Name = "IX_Post_Title" }, - "mb.DropIndex(" + _eol + " name: \"IX_Post_Title\");", +""" +mb.DropIndex( + name: "IX_Post_Title"); +""", o => { Assert.Equal("IX_Post_Title", o.Name); @@ -2144,7 +1938,12 @@ public void DropIndexOperation_all_args() Schema = "dbo", Table = "Post" }, - "mb.DropIndex(" + _eol + " name: \"IX_Post_Title\"," + _eol + " schema: \"dbo\"," + _eol + " table: \"Post\");", +""" +mb.DropIndex( + name: "IX_Post_Title", + schema: "dbo", + table: "Post"); +""", o => { Assert.Equal("IX_Post_Title", o.Name); @@ -2156,7 +1955,11 @@ public void DropIndexOperation_all_args() public void DropPrimaryKeyOperation_required_args() => Test( new DropPrimaryKeyOperation { Name = "PK_Post", Table = "Post" }, - "mb.DropPrimaryKey(" + _eol + " name: \"PK_Post\"," + _eol + " table: \"Post\");", +""" +mb.DropPrimaryKey( + name: "PK_Post", + table: "Post"); +""", o => { Assert.Equal("PK_Post", o.Name); @@ -2172,7 +1975,12 @@ public void DropPrimaryKeyOperation_all_args() Schema = "dbo", Table = "Post" }, - "mb.DropPrimaryKey(" + _eol + " name: \"PK_Post\"," + _eol + " schema: \"dbo\"," + _eol + " table: \"Post\");", +""" +mb.DropPrimaryKey( + name: "PK_Post", + schema: "dbo", + table: "Post"); +""", o => { Assert.Equal("PK_Post", o.Name); @@ -2184,21 +1992,31 @@ public void DropPrimaryKeyOperation_all_args() public void DropSchemaOperation_required_args() => Test( new DropSchemaOperation { Name = "my" }, - "mb.DropSchema(" + _eol + " name: \"my\");", +""" +mb.DropSchema( + name: "my"); +""", o => Assert.Equal("my", o.Name)); [ConditionalFact] public void DropSequenceOperation_required_args() => Test( new DropSequenceOperation { Name = "EntityFrameworkHiLoSequence" }, - "mb.DropSequence(" + _eol + " name: \"EntityFrameworkHiLoSequence\");", +""" +mb.DropSequence( + name: "EntityFrameworkHiLoSequence"); +""", o => Assert.Equal("EntityFrameworkHiLoSequence", o.Name)); [ConditionalFact] public void DropSequenceOperation_all_args() => Test( new DropSequenceOperation { Name = "EntityFrameworkHiLoSequence", Schema = "dbo" }, - "mb.DropSequence(" + _eol + " name: \"EntityFrameworkHiLoSequence\"," + _eol + " schema: \"dbo\");", +""" +mb.DropSequence( + name: "EntityFrameworkHiLoSequence", + schema: "dbo"); +""", o => { Assert.Equal("EntityFrameworkHiLoSequence", o.Name); @@ -2209,14 +2027,21 @@ public void DropSequenceOperation_all_args() public void DropTableOperation_required_args() => Test( new DropTableOperation { Name = "Post" }, - "mb.DropTable(" + _eol + " name: \"Post\");", +""" +mb.DropTable( + name: "Post"); +""", o => Assert.Equal("Post", o.Name)); [ConditionalFact] public void DropTableOperation_all_args() => Test( new DropTableOperation { Name = "Post", Schema = "dbo" }, - "mb.DropTable(" + _eol + " name: \"Post\"," + _eol + " schema: \"dbo\");", +""" +mb.DropTable( + name: "Post", + schema: "dbo"); +""", o => { Assert.Equal("Post", o.Name); @@ -2227,7 +2052,11 @@ public void DropTableOperation_all_args() public void DropUniqueConstraintOperation_required_args() => Test( new DropUniqueConstraintOperation { Name = "AK_Post_AltId", Table = "Post" }, - "mb.DropUniqueConstraint(" + _eol + " name: \"AK_Post_AltId\"," + _eol + " table: \"Post\");", +""" +mb.DropUniqueConstraint( + name: "AK_Post_AltId", + table: "Post"); +""", o => { Assert.Equal("AK_Post_AltId", o.Name); @@ -2243,13 +2072,12 @@ public void DropUniqueConstraintOperation_all_args() Schema = "dbo", Table = "Post" }, - "mb.DropUniqueConstraint(" - + _eol - + " name: \"AK_Post_AltId\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"Post\");", +""" +mb.DropUniqueConstraint( + name: "AK_Post_AltId", + schema: "dbo", + table: "Post"); +""", o => { Assert.Equal("AK_Post_AltId", o.Name); @@ -2261,7 +2089,11 @@ public void DropUniqueConstraintOperation_all_args() public void DropCheckConstraintOperation_required_args() => Test( new DropCheckConstraintOperation { Name = "CK_Post_AltId1_AltId2", Table = "Post" }, - "mb.DropCheckConstraint(" + _eol + " name: \"CK_Post_AltId1_AltId2\"," + _eol + " table: \"Post\");", +""" +mb.DropCheckConstraint( + name: "CK_Post_AltId1_AltId2", + table: "Post"); +""", o => { Assert.Equal("CK_Post_AltId1_AltId2", o.Name); @@ -2277,13 +2109,12 @@ public void DropCheckConstraintOperation_all_args() Schema = "dbo", Table = "Post" }, - "mb.DropCheckConstraint(" - + _eol - + " name: \"CK_Post_AltId1_AltId2\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"Post\");", +""" +mb.DropCheckConstraint( + name: "CK_Post_AltId1_AltId2", + schema: "dbo", + table: "Post"); +""", o => { Assert.Equal("CK_Post_AltId1_AltId2", o.Name); @@ -2300,7 +2131,12 @@ public void RenameColumnOperation_required_args() Table = "Post", NewName = "PostId" }, - "mb.RenameColumn(" + _eol + " name: \"Id\"," + _eol + " table: \"Post\"," + _eol + " newName: \"PostId\");", +""" +mb.RenameColumn( + name: "Id", + table: "Post", + newName: "PostId"); +""", o => { Assert.Equal("Id", o.Name); @@ -2318,15 +2154,13 @@ public void RenameColumnOperation_all_args() Table = "Post", NewName = "PostId" }, - "mb.RenameColumn(" - + _eol - + " name: \"Id\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"Post\"," - + _eol - + " newName: \"PostId\");", +""" +mb.RenameColumn( + name: "Id", + schema: "dbo", + table: "Post", + newName: "PostId"); +""", o => { Assert.Equal("Id", o.Name); @@ -2339,11 +2173,11 @@ public void RenameColumnOperation_all_args() public void RenameIndexOperation_required_args() => Test( new RenameIndexOperation { Name = "IX_Post_Title", NewName = "IX_Post_PostTitle" }, - "mb.RenameIndex(" - + _eol - + " name: \"IX_Post_Title\"," - + _eol - + " newName: \"IX_Post_PostTitle\");", +""" +mb.RenameIndex( + name: "IX_Post_Title", + newName: "IX_Post_PostTitle"); +""", o => { Assert.Equal("IX_Post_Title", o.Name); @@ -2360,15 +2194,13 @@ public void RenameIndexOperation_all_args() Table = "Post", NewName = "IX_dbo.Post_PostTitle" }, - "mb.RenameIndex(" - + _eol - + " name: \"IX_dbo.Post_Title\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"Post\"," - + _eol - + " newName: \"IX_dbo.Post_PostTitle\");", +""" +mb.RenameIndex( + name: "IX_dbo.Post_Title", + schema: "dbo", + table: "Post", + newName: "IX_dbo.Post_PostTitle"); +""", o => { Assert.Equal("IX_dbo.Post_Title", o.Name); @@ -2381,7 +2213,10 @@ public void RenameIndexOperation_all_args() public void RenameSequenceOperation_required_args() => Test( new RenameSequenceOperation { Name = "EntityFrameworkHiLoSequence" }, - "mb.RenameSequence(" + _eol + " name: \"EntityFrameworkHiLoSequence\");", +""" +mb.RenameSequence( + name: "EntityFrameworkHiLoSequence"); +""", o => Assert.Equal("EntityFrameworkHiLoSequence", o.Name)); [ConditionalFact] @@ -2394,15 +2229,13 @@ public void RenameSequenceOperation_all_args() NewName = "MySequence", NewSchema = "my" }, - "mb.RenameSequence(" - + _eol - + " name: \"EntityFrameworkHiLoSequence\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " newName: \"MySequence\"," - + _eol - + " newSchema: \"my\");", +""" +mb.RenameSequence( + name: "EntityFrameworkHiLoSequence", + schema: "dbo", + newName: "MySequence", + newSchema: "my"); +""", o => { Assert.Equal("EntityFrameworkHiLoSequence", o.Name); @@ -2415,7 +2248,10 @@ public void RenameSequenceOperation_all_args() public void RenameTableOperation_required_args() => Test( new RenameTableOperation { Name = "Post" }, - "mb.RenameTable(" + _eol + " name: \"Post\");", +""" +mb.RenameTable( + name: "Post"); +""", o => Assert.Equal("Post", o.Name)); [ConditionalFact] @@ -2428,15 +2264,13 @@ public void RenameTableOperation_all_args() NewName = "Posts", NewSchema = "my" }, - "mb.RenameTable(" - + _eol - + " name: \"Post\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " newName: \"Posts\"," - + _eol - + " newSchema: \"my\");", +""" +mb.RenameTable( + name: "Post", + schema: "dbo", + newName: "Posts", + newSchema: "my"); +""", o => { Assert.Equal("Post", o.Name); @@ -2449,7 +2283,11 @@ public void RenameTableOperation_all_args() public void RestartSequenceOperation_required_args() => Test( new RestartSequenceOperation { Name = "EntityFrameworkHiLoSequence", StartValue = 1 }, - "mb.RestartSequence(" + _eol + " name: \"EntityFrameworkHiLoSequence\"," + _eol + " startValue: 1L);", +""" +mb.RestartSequence( + name: "EntityFrameworkHiLoSequence", + startValue: 1L); +""", o => { Assert.Equal("EntityFrameworkHiLoSequence", o.Name); @@ -2465,13 +2303,12 @@ public void RestartSequenceOperation_all_args() Schema = "dbo", StartValue = 1 }, - "mb.RestartSequence(" - + _eol - + " name: \"EntityFrameworkHiLoSequence\"," - + _eol - + " schema: \"dbo\"," - + _eol - + " startValue: 1L);", +""" +mb.RestartSequence( + name: "EntityFrameworkHiLoSequence", + schema: "dbo", + startValue: 1L); +""", o => { Assert.Equal("EntityFrameworkHiLoSequence", o.Name); @@ -2546,35 +2383,23 @@ public void InsertDataOperation_all_args() { 7, "Aemon Targaryen", _geometryCollection } } }, - "mb.InsertData(" - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"People\"," - + _eol - + " columns: new[] { \"Id\", \"Full Name\", \"Geometry\" }," - + _eol - + " values: new object[,]" - + _eol - + " {" - + _eol - + " { 0, null, null }," - + _eol - + " { 1, \"Daenerys Targaryen\", (NetTopologySuite.Geometries.Point)new NetTopologySuite.IO.WKTReader().Read(\"SRID=4326;POINT Z(1.1 2.2 3.3)\") }," - + _eol - + " { 2, \"John Snow\", (NetTopologySuite.Geometries.Polygon)new NetTopologySuite.IO.WKTReader().Read(\"SRID=4326;POLYGON ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2))\") }," - + _eol - + " { 3, \"Arya Stark\", (NetTopologySuite.Geometries.LineString)new NetTopologySuite.IO.WKTReader().Read(\"SRID=4326;LINESTRING (1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2)\") }," - + _eol - + " { 4, \"Harry Strickland\", (NetTopologySuite.Geometries.MultiPoint)new NetTopologySuite.IO.WKTReader().Read(\"SRID=4326;MULTIPOINT ((1.1 2.2), (2.2 2.2), (2.2 1.1))\") }," - + _eol - + " { 5, \"The Imp\", (NetTopologySuite.Geometries.MultiPolygon)new NetTopologySuite.IO.WKTReader().Read(\"SRID=4326;MULTIPOLYGON (((10.1 20.2, 20.2 20.2, 20.2 10.1, 10.1 20.2)), ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2)))\") }," - + _eol - + " { 6, \"The Kingslayer\", (NetTopologySuite.Geometries.MultiLineString)new NetTopologySuite.IO.WKTReader().Read(\"SRID=4326;MULTILINESTRING ((1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2), (7.1 7.2, 20.2 20.2, 20.2 1.1, 70.1 70.2))\") }," - + _eol - + " { 7, \"Aemon Targaryen\", (NetTopologySuite.Geometries.GeometryCollection)new NetTopologySuite.IO.WKTReader().Read(\"SRID=4326;GEOMETRYCOLLECTION Z(LINESTRING Z(1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), LINESTRING Z(7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN), MULTIPOINT Z((1.1 2.2 NaN), (2.2 2.2 NaN), (2.2 1.1 NaN)), POLYGON Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN)), POLYGON Z((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), POINT Z(1.1 2.2 3.3), MULTILINESTRING Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), (7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN)), MULTIPOLYGON Z(((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), ((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN))))\") }" - + _eol - + " });", +""" +mb.InsertData( + schema: "dbo", + table: "People", + columns: new[] { "Id", "Full Name", "Geometry" }, + values: new object[,] + { + { 0, null, null }, + { 1, "Daenerys Targaryen", (NetTopologySuite.Geometries.Point)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;POINT Z(1.1 2.2 3.3)") }, + { 2, "John Snow", (NetTopologySuite.Geometries.Polygon)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;POLYGON ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2))") }, + { 3, "Arya Stark", (NetTopologySuite.Geometries.LineString)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;LINESTRING (1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2)") }, + { 4, "Harry Strickland", (NetTopologySuite.Geometries.MultiPoint)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTIPOINT ((1.1 2.2), (2.2 2.2), (2.2 1.1))") }, + { 5, "The Imp", (NetTopologySuite.Geometries.MultiPolygon)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTIPOLYGON (((10.1 20.2, 20.2 20.2, 20.2 10.1, 10.1 20.2)), ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2)))") }, + { 6, "The Kingslayer", (NetTopologySuite.Geometries.MultiLineString)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTILINESTRING ((1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2), (7.1 7.2, 20.2 20.2, 20.2 1.1, 70.1 70.2))") }, + { 7, "Aemon Targaryen", (NetTopologySuite.Geometries.GeometryCollection)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;GEOMETRYCOLLECTION Z(LINESTRING Z(1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), LINESTRING Z(7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN), MULTIPOINT Z((1.1 2.2 NaN), (2.2 2.2 NaN), (2.2 1.1 NaN)), POLYGON Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN)), POLYGON Z((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), POINT Z(1.1 2.2 3.3), MULTILINESTRING Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), (7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN)), MULTIPOLYGON Z(((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), ((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN))))") } + }); +""", o => { Assert.Equal("dbo", o.Schema); @@ -2601,13 +2426,12 @@ public void InsertDataOperation_required_args() Columns = new[] { "Geometry" }, Values = new object[,] { { _point1 } } }, - "mb.InsertData(" - + _eol - + " table: \"People\"," - + _eol - + " column: \"Geometry\"," - + _eol - + " value: (NetTopologySuite.Geometries.Point)new NetTopologySuite.IO.WKTReader().Read(\"SRID=4326;POINT Z(1.1 2.2 3.3)\"));", +""" +mb.InsertData( + table: "People", + column: "Geometry", + value: (NetTopologySuite.Geometries.Point)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;POINT Z(1.1 2.2 3.3)")); +""", o => { Assert.Equal("People", o.Table); @@ -2626,13 +2450,12 @@ public void InsertDataOperation_required_empty_array() Columns = new[] { "Tags" }, Values = new object[,] { { new string[0] } } }, - "mb.InsertData(" - + _eol - + " table: \"People\"," - + _eol - + " column: \"Tags\"," - + _eol - + " value: new string[0]);", +""" +mb.InsertData( + table: "People", + column: "Tags", + value: new string[0]); +""", o => { Assert.Equal("People", o.Table); @@ -2651,13 +2474,12 @@ public void InsertDataOperation_required_empty_array_composite() Columns = new[] { "First Name", "Last Name", "Geometry" }, Values = new object[,] { { "John", null, new string[0] } } }, - "mb.InsertData(" - + _eol - + " table: \"People\"," - + _eol - + " columns: new[] { \"First Name\", \"Last Name\", \"Geometry\" }," - + _eol - + " values: new object[] { \"John\", null, new string[0] });", +""" +mb.InsertData( + table: "People", + columns: new[] { "First Name", "Last Name", "Geometry" }, + values: new object[] { "John", null, new string[0] }); +""", o => { Assert.Equal("People", o.Table); @@ -2677,13 +2499,12 @@ public void InsertDataOperation_required_args_composite() Columns = new[] { "First Name", "Last Name", "Geometry" }, Values = new object[,] { { "John", "Snow", _polygon1 } } }, - "mb.InsertData(" - + _eol - + " table: \"People\"," - + _eol - + " columns: new[] { \"First Name\", \"Last Name\", \"Geometry\" }," - + _eol - + " values: new object[] { \"John\", \"Snow\", (NetTopologySuite.Geometries.Polygon)new NetTopologySuite.IO.WKTReader().Read(\"SRID=4326;POLYGON ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2))\") });", +""" +mb.InsertData( + table: "People", + columns: new[] { "First Name", "Last Name", "Geometry" }, + values: new object[] { "John", "Snow", (NetTopologySuite.Geometries.Polygon)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;POLYGON ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2))") }); +""", o => { Assert.Equal("People", o.Table); @@ -2703,21 +2524,16 @@ public void InsertDataOperation_required_args_multiple_rows() Columns = new[] { "Geometries" }, Values = new object[,] { { _lineString1 }, { _multiPoint } } }, - "mb.InsertData(" - + _eol - + " table: \"People\"," - + _eol - + " column: \"Geometries\"," - + _eol - + " values: new object[]" - + _eol - + " {" - + _eol - + " (NetTopologySuite.Geometries.LineString)new NetTopologySuite.IO.WKTReader().Read(\"SRID=4326;LINESTRING (1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2)\")," - + _eol - + " (NetTopologySuite.Geometries.MultiPoint)new NetTopologySuite.IO.WKTReader().Read(\"SRID=4326;MULTIPOINT ((1.1 2.2), (2.2 2.2), (2.2 1.1))\")" - + _eol - + " });", +""" +mb.InsertData( + table: "People", + column: "Geometries", + values: new object[] + { + (NetTopologySuite.Geometries.LineString)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;LINESTRING (1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2)"), + (NetTopologySuite.Geometries.MultiPoint)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTIPOINT ((1.1 2.2), (2.2 2.2), (2.2 1.1))") + }); +""", o => { Assert.Equal("People", o.Table); @@ -2743,25 +2559,18 @@ public void InsertDataOperation_args_with_linebreaks() { 2, "Contains a single Backslash r,\rjust in case" }, } }, - "mb.InsertData(" - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"TestLineBreaks\"," - + _eol - + " columns: new[] { \"Id\", \"Description\" }," - + _eol - + " values: new object[,]" - + _eol - + " {" - + _eol - + " { 0, \"Contains\\r\\na Windows linebreak\" }," - + _eol - + " { 1, \"Contains a\\nLinux linebreak\" }," - + _eol - + " { 2, \"Contains a single Backslash r,\\rjust in case\" }" - + _eol - + " });", +$$""" +mb.InsertData( + schema: "dbo", + table: "TestLineBreaks", + columns: new[] { "Id", "Description" }, + values: new object[,] + { + { 0, "Contains{{"\\r\\n"}}a Windows linebreak" }, + { 1, "Contains a{{"\\n"}}Linux linebreak" }, + { 2, "Contains a single Backslash r,{{"\\r"}}just in case" } + }); +""", operation => { Assert.Equal("dbo", operation.Schema); @@ -2785,31 +2594,21 @@ public void DeleteDataOperation_all_args() KeyColumnTypes = new[] { "string" }, KeyValues = new object[,] { { "Hodor" }, { "Daenerys" }, { "John" }, { "Arya" }, { "Harry" } } }, - "mb.DeleteData(" - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"People\"," - + _eol - + " keyColumn: \"First Name\"," - + _eol - + " keyColumnType: \"string\"," - + _eol - + " keyValues: new object[]" - + _eol - + " {" - + _eol - + " \"Hodor\"," - + _eol - + " \"Daenerys\"," - + _eol - + " \"John\"," - + _eol - + " \"Arya\"," - + _eol - + " \"Harry\"" - + _eol - + " });", +""" +mb.DeleteData( + schema: "dbo", + table: "People", + keyColumn: "First Name", + keyColumnType: "string", + keyValues: new object[] + { + "Hodor", + "Daenerys", + "John", + "Arya", + "Harry" + }); +""", o => { Assert.Equal("dbo", o.Schema); @@ -2833,29 +2632,20 @@ public void DeleteDataOperation_all_args_composite() { "Hodor", null }, { "Daenerys", "Targaryen" }, { "John", "Snow" }, { "Arya", "Stark" }, { "Harry", "Strickland" } } }, - "mb.DeleteData(" - + _eol - + " table: \"People\"," - + _eol - + " keyColumns: new[] { \"First Name\", \"Last Name\" }," - + _eol - + " keyColumnTypes: new[] { \"string\", \"string\" }," - + _eol - + " keyValues: new object[,]" - + _eol - + " {" - + _eol - + " { \"Hodor\", null }," - + _eol - + " { \"Daenerys\", \"Targaryen\" }," - + _eol - + " { \"John\", \"Snow\" }," - + _eol - + " { \"Arya\", \"Stark\" }," - + _eol - + " { \"Harry\", \"Strickland\" }" - + _eol - + " });", +""" +mb.DeleteData( + table: "People", + keyColumns: new[] { "First Name", "Last Name" }, + keyColumnTypes: new[] { "string", "string" }, + keyValues: new object[,] + { + { "Hodor", null }, + { "Daenerys", "Targaryen" }, + { "John", "Snow" }, + { "Arya", "Stark" }, + { "Harry", "Strickland" } + }); +""", o => { Assert.Equal("People", o.Table); @@ -2874,13 +2664,12 @@ public void DeleteDataOperation_required_args() KeyColumns = new[] { "Last Name" }, KeyValues = new object[,] { { "Snow" } } }, - "mb.DeleteData(" - + _eol - + " table: \"People\"," - + _eol - + " keyColumn: \"Last Name\"," - + _eol - + " keyValue: \"Snow\");", +""" +mb.DeleteData( + table: "People", + keyColumn: "Last Name", + keyValue: "Snow"); +""", o => { Assert.Equal("People", o.Table); @@ -2899,13 +2688,12 @@ public void DeleteDataOperation_required_args_composite() KeyColumns = new[] { "First Name", "Last Name" }, KeyValues = new object[,] { { "John", "Snow" } } }, - "mb.DeleteData(" - + _eol - + " table: \"People\"," - + _eol - + " keyColumns: new[] { \"First Name\", \"Last Name\" }," - + _eol - + " keyValues: new object[] { \"John\", \"Snow\" });", +""" +mb.DeleteData( + table: "People", + keyColumns: new[] { "First Name", "Last Name" }, + keyValues: new object[] { "John", "Snow" }); +""", o => { Assert.Equal("People", o.Table); @@ -2929,23 +2717,17 @@ public void DeleteDataOperation_args_with_linebreaks() { 2, "Contains a single Backslash r,\rjust in case" }, } }, - "mb.DeleteData(" - + _eol - + " table: \"TestLineBreaks\"," - + _eol - + " keyColumns: new[] { \"Id\", \"Description\" }," - + _eol - + " keyValues: new object[,]" - + _eol - + " {" - + _eol - + " { 0, \"Contains\\r\\na Windows linebreak\" }," - + _eol - + " { 1, \"Contains a\\nLinux linebreak\" }," - + _eol - + " { 2, \"Contains a single Backslash r,\\rjust in case\" }" - + _eol - + " });", +$$""" +mb.DeleteData( + table: "TestLineBreaks", + keyColumns: new[] { "Id", "Description" }, + keyValues: new object[,] + { + { 0, "Contains{{"\\r\\n"}}a Windows linebreak" }, + { 1, "Contains a{{"\\n"}}Linux linebreak" }, + { 2, "Contains a single Backslash r,{{"\\r"}}just in case" } + }); +""", operation => { Assert.Equal("TestLineBreaks", operation.Table); @@ -2969,35 +2751,23 @@ public void UpdateDataOperation_all_args() Columns = new[] { "Birthplace", "House Allegiance", "Culture" }, Values = new object[,] { { "Winterfell", "Stark", "Northmen" }, { "Dragonstone", "Targaryen", "Valyrian" } } }, - "mb.UpdateData(" - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"People\"," - + _eol - + " keyColumn: \"First Name\"," - + _eol - + " keyValues: new object[]" - + _eol - + " {" - + _eol - + " \"Hodor\"," - + _eol - + " \"Daenerys\"" - + _eol - + " }," - + _eol - + " columns: new[] { \"Birthplace\", \"House Allegiance\", \"Culture\" }," - + _eol - + " values: new object[,]" - + _eol - + " {" - + _eol - + " { \"Winterfell\", \"Stark\", \"Northmen\" }," - + _eol - + " { \"Dragonstone\", \"Targaryen\", \"Valyrian\" }" - + _eol - + " });", +""" +mb.UpdateData( + schema: "dbo", + table: "People", + keyColumn: "First Name", + keyValues: new object[] + { + "Hodor", + "Daenerys" + }, + columns: new[] { "Birthplace", "House Allegiance", "Culture" }, + values: new object[,] + { + { "Winterfell", "Stark", "Northmen" }, + { "Dragonstone", "Targaryen", "Valyrian" } + }); +""", o => { Assert.Equal("dbo", o.Schema); @@ -3023,33 +2793,22 @@ public void UpdateDataOperation_all_args_composite() Columns = new[] { "House Allegiance" }, Values = new object[,] { { "Stark" }, { "Targaryen" } } }, - "mb.UpdateData(" - + _eol - + " table: \"People\"," - + _eol - + " keyColumns: new[] { \"First Name\", \"Last Name\" }," - + _eol - + " keyValues: new object[,]" - + _eol - + " {" - + _eol - + " { \"Hodor\", null }," - + _eol - + " { \"Daenerys\", \"Targaryen\" }" - + _eol - + " }," - + _eol - + " column: \"House Allegiance\"," - + _eol - + " values: new object[]" - + _eol - + " {" - + _eol - + " \"Stark\"," - + _eol - + " \"Targaryen\"" - + _eol - + " });", +""" +mb.UpdateData( + table: "People", + keyColumns: new[] { "First Name", "Last Name" }, + keyValues: new object[,] + { + { "Hodor", null }, + { "Daenerys", "Targaryen" } + }, + column: "House Allegiance", + values: new object[] + { + "Stark", + "Targaryen" + }); +""", o => { Assert.Equal("People", o.Table); @@ -3074,33 +2833,22 @@ public void UpdateDataOperation_all_args_composite_multi() Columns = new[] { "Birthplace", "House Allegiance", "Culture" }, Values = new object[,] { { "Winterfell", "Stark", "Northmen" }, { "Dragonstone", "Targaryen", "Valyrian" } } }, - "mb.UpdateData(" - + _eol - + " table: \"People\"," - + _eol - + " keyColumns: new[] { \"First Name\", \"Last Name\" }," - + _eol - + " keyValues: new object[,]" - + _eol - + " {" - + _eol - + " { \"Hodor\", null }," - + _eol - + " { \"Daenerys\", \"Targaryen\" }" - + _eol - + " }," - + _eol - + " columns: new[] { \"Birthplace\", \"House Allegiance\", \"Culture\" }," - + _eol - + " values: new object[,]" - + _eol - + " {" - + _eol - + " { \"Winterfell\", \"Stark\", \"Northmen\" }," - + _eol - + " { \"Dragonstone\", \"Targaryen\", \"Valyrian\" }" - + _eol - + " });", +""" +mb.UpdateData( + table: "People", + keyColumns: new[] { "First Name", "Last Name" }, + keyValues: new object[,] + { + { "Hodor", null }, + { "Daenerys", "Targaryen" } + }, + columns: new[] { "Birthplace", "House Allegiance", "Culture" }, + values: new object[,] + { + { "Winterfell", "Stark", "Northmen" }, + { "Dragonstone", "Targaryen", "Valyrian" } + }); +""", o => { Assert.Equal("People", o.Table); @@ -3126,19 +2874,15 @@ public void UpdateDataOperation_all_args_multi() Columns = new[] { "Birthplace", "House Allegiance", "Culture" }, Values = new object[,] { { "Dragonstone", "Targaryen", "Valyrian" } } }, - "mb.UpdateData(" - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"People\"," - + _eol - + " keyColumn: \"Full Name\"," - + _eol - + " keyValue: \"Daenerys Targaryen\"," - + _eol - + " columns: new[] { \"Birthplace\", \"House Allegiance\", \"Culture\" }," - + _eol - + " values: new object[] { \"Dragonstone\", \"Targaryen\", \"Valyrian\" });", +""" +mb.UpdateData( + schema: "dbo", + table: "People", + keyColumn: "Full Name", + keyValue: "Daenerys Targaryen", + columns: new[] { "Birthplace", "House Allegiance", "Culture" }, + values: new object[] { "Dragonstone", "Targaryen", "Valyrian" }); +""", o => { Assert.Equal("dbo", o.Schema); @@ -3164,17 +2908,14 @@ public void UpdateDataOperation_required_args() Columns = new[] { "House Allegiance" }, Values = new object[,] { { "Targaryen" } } }, - "mb.UpdateData(" - + _eol - + " table: \"People\"," - + _eol - + " keyColumn: \"First Name\"," - + _eol - + " keyValue: \"Daenerys\"," - + _eol - + " column: \"House Allegiance\"," - + _eol - + " value: \"Targaryen\");", +""" +mb.UpdateData( + table: "People", + keyColumn: "First Name", + keyValue: "Daenerys", + column: "House Allegiance", + value: "Targaryen"); +""", o => { Assert.Equal("People", o.Table); @@ -3199,33 +2940,22 @@ public void UpdateDataOperation_required_args_multiple_rows() Columns = new[] { "House Allegiance" }, Values = new object[,] { { "Stark" }, { "Targaryen" } } }, - "mb.UpdateData(" - + _eol - + " table: \"People\"," - + _eol - + " keyColumn: \"First Name\"," - + _eol - + " keyValues: new object[]" - + _eol - + " {" - + _eol - + " \"Hodor\"," - + _eol - + " \"Daenerys\"" - + _eol - + " }," - + _eol - + " column: \"House Allegiance\"," - + _eol - + " values: new object[]" - + _eol - + " {" - + _eol - + " \"Stark\"," - + _eol - + " \"Targaryen\"" - + _eol - + " });", +""" +mb.UpdateData( + table: "People", + keyColumn: "First Name", + keyValues: new object[] + { + "Hodor", + "Daenerys" + }, + column: "House Allegiance", + values: new object[] + { + "Stark", + "Targaryen" + }); +""", o => { Assert.Equal("People", o.Table); @@ -3250,17 +2980,14 @@ public void UpdateDataOperation_required_args_composite() Columns = new[] { "House Allegiance" }, Values = new object[,] { { "Targaryen" } } }, - "mb.UpdateData(" - + _eol - + " table: \"People\"," - + _eol - + " keyColumns: new[] { \"First Name\", \"Last Name\" }," - + _eol - + " keyValues: new object[] { \"Daenerys\", \"Targaryen\" }," - + _eol - + " column: \"House Allegiance\"," - + _eol - + " value: \"Targaryen\");", +""" +mb.UpdateData( + table: "People", + keyColumns: new[] { "First Name", "Last Name" }, + keyValues: new object[] { "Daenerys", "Targaryen" }, + column: "House Allegiance", + value: "Targaryen"); +""", o => { Assert.Equal("People", o.Table); @@ -3285,17 +3012,14 @@ public void UpdateDataOperation_required_args_composite_multi() Columns = new[] { "Birthplace", "House Allegiance", "Culture" }, Values = new object[,] { { "Dragonstone", "Targaryen", "Valyrian" } } }, - "mb.UpdateData(" - + _eol - + " table: \"People\"," - + _eol - + " keyColumns: new[] { \"First Name\", \"Last Name\" }," - + _eol - + " keyValues: new object[] { \"Daenerys\", \"Targaryen\" }," - + _eol - + " columns: new[] { \"Birthplace\", \"House Allegiance\", \"Culture\" }," - + _eol - + " values: new object[] { \"Dragonstone\", \"Targaryen\", \"Valyrian\" });", +""" +mb.UpdateData( + table: "People", + keyColumns: new[] { "First Name", "Last Name" }, + keyValues: new object[] { "Daenerys", "Targaryen" }, + columns: new[] { "Birthplace", "House Allegiance", "Culture" }, + values: new object[] { "Dragonstone", "Targaryen", "Valyrian" }); +""", o => { Assert.Equal("People", o.Table); @@ -3320,17 +3044,14 @@ public void UpdateDataOperation_required_args_multi() Columns = new[] { "Birthplace", "House Allegiance", "Culture" }, Values = new object[,] { { "Dragonstone", "Targaryen", "Valyrian" } } }, - "mb.UpdateData(" - + _eol - + " table: \"People\"," - + _eol - + " keyColumn: \"Full Name\"," - + _eol - + " keyValue: \"Daenerys Targaryen\"," - + _eol - + " columns: new[] { \"Birthplace\", \"House Allegiance\", \"Culture\" }," - + _eol - + " values: new object[] { \"Dragonstone\", \"Targaryen\", \"Valyrian\" });", +""" +mb.UpdateData( + table: "People", + keyColumn: "Full Name", + keyValue: "Daenerys Targaryen", + columns: new[] { "Birthplace", "House Allegiance", "Culture" }, + values: new object[] { "Dragonstone", "Targaryen", "Valyrian" }); +""", o => { Assert.Equal("People", o.Table); @@ -3361,39 +3082,25 @@ public void UpdateDataOperation_with_linebreaks() { "Contains a single Backslash r,\rjust in case" }, } }, - "mb.UpdateData(" - + _eol - + " schema: \"dbo\"," - + _eol - + " table: \"TestLineBreaks\"," - + _eol - + " keyColumn: \"Id\"," - + _eol - + " keyValues: new object[]" - + _eol - + " {" - + _eol - + " 0," - + _eol - + " 1," - + _eol - + " 2" - + _eol - + " }," - + _eol - + " column: \"Description\"," - + _eol - + " values: new object[]" - + _eol - + " {" - + _eol - + " \"Contains\\r\\na Windows linebreak\"," - + _eol - + " \"Contains a\\nLinux linebreak\"," - + _eol - + " \"Contains a single Backslash r,\\rjust in case\"" - + _eol - + " });", +$$""" +mb.UpdateData( + schema: "dbo", + table: "TestLineBreaks", + keyColumn: "Id", + keyValues: new object[] + { + 0, + 1, + 2 + }, + column: "Description", + values: new object[] + { + "Contains{{"\\r\\n"}}a Windows linebreak", + "Contains a{{"\\n"}}Linux linebreak", + "Contains a single Backslash r,{{"\\r"}}just in case" + }); +""", operation => { Assert.Equal("dbo", operation.Schema); @@ -3423,17 +3130,14 @@ public void AlterTableOperation_annotation_set_to_null() Test( alterTable, - "mb.AlterTable(" - + _eol - + " name: \"NewCustomer\")" - + _eol - + " .Annotation(\"MyAnnotation1\", null)" - + _eol - + " .Annotation(\"MyAnnotation2\", \"Foo\")" - + _eol - + " .OldAnnotation(\"MyAnnotation1\", \"Bar\")" - + _eol - + " .OldAnnotation(\"MyAnnotation2\", null);", +""" +mb.AlterTable( + name: "NewCustomer") + .Annotation("MyAnnotation1", null) + .Annotation("MyAnnotation2", "Foo") + .OldAnnotation("MyAnnotation1", "Bar") + .OldAnnotation("MyAnnotation2", null); +""", operation => { Assert.Equal("NewCustomer", operation.Name); @@ -3460,7 +3164,7 @@ private void Test(T operation, string expectedCode, Action assert) generator.Generate("mb", new[] { operation }, builder); var code = builder.ToString(); - Assert.Equal(expectedCode, code); + Assert.Equal(expectedCode, code, ignoreLineEndingDifferences: true); var build = new BuildSource { @@ -3468,7 +3172,8 @@ private void Test(T operation, string expectedCode, Action assert) Sources = { { - "Migration.cs", @" + "Migration.cs", +$$""" using Microsoft.EntityFrameworkCore.Migrations; using NetTopologySuite.Geometries; @@ -3478,12 +3183,10 @@ public static class OperationsFactory { public static void Create(MigrationBuilder mb) { - " - + code - + @" + {{code}} } } - " +""" } } }; diff --git a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.cs b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.cs index cc263455264..ebcb88ac907 100644 --- a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.cs @@ -550,7 +550,8 @@ public void Migrations_compile() }, Array.Empty()); Assert.Equal( - @"using System.Text.RegularExpressions; +""" +using System.Text.RegularExpressions; using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Migrations; @@ -566,23 +567,23 @@ public partial class MyMigration : Migration /// protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.Sql(""-- TEST"") - .Annotation(""Some:EnumValue"", RegexOptions.Multiline); + migrationBuilder.Sql("-- TEST") + .Annotation("Some:EnumValue", RegexOptions.Multiline); migrationBuilder.AlterColumn( - name: ""C2"", - table: ""T1"", + name: "C2", + table: "T1", nullable: false, oldClrType: typeof(Property)); migrationBuilder.AddColumn( - name: ""C3"", - table: ""T1"", + name: "C3", + table: "T1", nullable: false); migrationBuilder.InsertData( - table: ""T1"", - columns: new[] { ""Id"", ""C2"", ""C3"" }, + table: "T1", + columns: new[] { "Id", "C2", "C3" }, values: new object[] { 1, null, -1 }); } @@ -593,7 +594,8 @@ protected override void Down(MigrationBuilder migrationBuilder) } } } -", + +""", migrationCode, ignoreLineEndingDifferences: true); @@ -619,7 +621,8 @@ protected override void Down(MigrationBuilder migrationBuilder) "20150511161616_MyMigration", finalizedModel); Assert.Equal( - @"// +""" +// using System.Text.RegularExpressions; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -632,36 +635,37 @@ protected override void Down(MigrationBuilder migrationBuilder) namespace MyNamespace { [DbContext(typeof(CSharpMigrationsGeneratorTest.MyContext))] - [Migration(""20150511161616_MyMigration"")] + [Migration("20150511161616_MyMigration")] partial class MyMigration { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder.HasAnnotation(""Some:EnumValue"", RegexOptions.Multiline); + modelBuilder.HasAnnotation("Some:EnumValue", RegexOptions.Multiline); - modelBuilder.Entity(""T1"", b => + modelBuilder.Entity("T1", b => { - b.Property(""Id"") - .HasColumnType(""int""); + b.Property("Id") + .HasColumnType("int"); - b.Property(""C2"") + b.Property("C2") .IsRequired() - .HasColumnType(""nvarchar(max)""); + .HasColumnType("nvarchar(max)"); - b.Property(""C3"") - .HasColumnType(""int""); + b.Property("C3") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""T1""); + b.ToTable("T1"); }); #pragma warning restore 612, 618 } } } -", + +""", migrationMetadataCode, ignoreLineEndingDifferences: true); @@ -753,7 +757,8 @@ public void Snapshots_compile() "MySnapshot", finalizedModel); Assert.Equal( - @"// +""" +// using System; using System.Text.RegularExpressions; using Microsoft.EntityFrameworkCore; @@ -771,39 +776,40 @@ partial class MySnapshot : ModelSnapshot protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder.HasAnnotation(""Some:EnumValue"", RegexOptions.Multiline); + modelBuilder.HasAnnotation("Some:EnumValue", RegexOptions.Multiline); - modelBuilder.Entity(""Cheese"", b => + modelBuilder.Entity("Cheese", b => { - b.Property(""Ham"") - .HasColumnType(""just_string(10)""); + b.Property("Ham") + .HasColumnType("just_string(10)"); - b.Property(""Pickle"") - .HasColumnType(""just_string(10)""); + b.Property("Pickle") + .HasColumnType("just_string(10)"); - b.HasKey(""Ham""); + b.HasKey("Ham"); - b.ToTable(""Cheese""); + b.ToTable("Cheese"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGeneratorTest+EntityWithConstructorBinding"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGeneratorTest+EntityWithConstructorBinding", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""default_int_mapping""); + .HasColumnType("default_int_mapping"); - b.Property(""PropertyWithValueGenerator"") - .HasColumnType(""default_guid_mapping""); + b.Property("PropertyWithValueGenerator") + .HasColumnType("default_guid_mapping"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithConstructorBinding""); + b.ToTable("EntityWithConstructorBinding"); }); #pragma warning restore 612, 618 } } } -", modelSnapshotCode, ignoreLineEndingDifferences: true); + +""", modelSnapshotCode, ignoreLineEndingDifferences: true); var snapshot = CompileModelSnapshot(modelSnapshotCode, "MyNamespace.MySnapshot"); Assert.Equal(2, snapshot.Model.GetEntityTypes().Count()); diff --git a/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs b/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs index fac37a476ce..90a2dfc4a64 100644 --- a/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs +++ b/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs @@ -329,15 +329,16 @@ public virtual void Model_annotations_are_stored_in_snapshot() .HasServiceTier("basic") .HasPerformanceLevel("S0"), AddBoilerPlate( - @" +""" modelBuilder - .HasAnnotation(""AnnotationName"", ""AnnotationValue"") - .HasAnnotation(""Relational:MaxIdentifierLength"", 128); + .HasAnnotation("AnnotationName", "AnnotationValue") + .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - SqlServerModelBuilderExtensions.HasDatabaseMaxSize(modelBuilder, ""100 MB""); - SqlServerModelBuilderExtensions.HasServiceTierSql(modelBuilder, ""'basic'""); - SqlServerModelBuilderExtensions.HasPerformanceLevelSql(modelBuilder, ""'S0'"");"), + SqlServerModelBuilderExtensions.HasDatabaseMaxSize(modelBuilder, "100 MB"); + SqlServerModelBuilderExtensions.HasServiceTierSql(modelBuilder, "'basic'"); + SqlServerModelBuilderExtensions.HasPerformanceLevelSql(modelBuilder, "'S0'"); +"""), o => { Assert.Equal(8, o.GetAnnotations().Count()); @@ -354,26 +355,27 @@ public virtual void Model_Fluent_APIs_are_properly_generated() builder.Ignore(); }, AddBoilerPlate( - @" - modelBuilder.HasAnnotation(""Relational:MaxIdentifierLength"", 128); +""" + modelBuilder.HasAnnotation("Relational:MaxIdentifierLength", 128); - SqlServerModelBuilderExtensions.UseHiLo(modelBuilder, ""EntityFrameworkHiLoSequence""); + SqlServerModelBuilderExtensions.UseHiLo(modelBuilder, "EntityFrameworkHiLoSequence"); - modelBuilder.HasSequence(""EntityFrameworkHiLoSequence"") + modelBuilder.HasSequence("EntityFrameworkHiLoSequence") .IncrementsBy(10); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseHiLo(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseHiLo(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); - });"), + b.ToTable("EntityWithOneProperty"); + }); +"""), o => { Assert.Equal(SqlServerValueGenerationStrategy.SequenceHiLo, o.GetValueGenerationStrategy()); @@ -392,26 +394,27 @@ public virtual void Model_fluent_APIs_for_sequence_key_are_properly_generated() builder.Ignore(); }, AddBoilerPlate( - @" - modelBuilder.HasAnnotation(""Relational:MaxIdentifierLength"", 128); +""" + modelBuilder.HasAnnotation("Relational:MaxIdentifierLength", 128); - SqlServerModelBuilderExtensions.UseKeySequences(modelBuilder, ""Sequence""); + SqlServerModelBuilderExtensions.UseKeySequences(modelBuilder, "Sequence"); - modelBuilder.HasSequence(""EntityWithOnePropertySequence""); + modelBuilder.HasSequence("EntityWithOnePropertySequence"); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int"") - .HasDefaultValueSql(""NEXT VALUE FOR [EntityWithOnePropertySequence]""); + .HasColumnType("int") + .HasDefaultValueSql("NEXT VALUE FOR [EntityWithOnePropertySequence]"); - SqlServerPropertyBuilderExtensions.UseSequence(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseSequence(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); - });"), + b.ToTable("EntityWithOneProperty"); + }); +"""), o => { Assert.Equal(SqlServerValueGenerationStrategy.Sequence, o.GetValueGenerationStrategy()); @@ -429,13 +432,14 @@ public virtual void Model_default_schema_annotation_is_stored_in_snapshot_as_flu builder.HasAnnotation("AnnotationName", "AnnotationValue"); }, AddBoilerPlate( - @" +""" modelBuilder - .HasDefaultSchema(""DefaultSchema"") - .HasAnnotation(""AnnotationName"", ""AnnotationValue"") - .HasAnnotation(""Relational:MaxIdentifierLength"", 128); + .HasDefaultSchema("DefaultSchema") + .HasAnnotation("AnnotationName", "AnnotationValue") + .HasAnnotation("Relational:MaxIdentifierLength", 128); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);"), + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); +"""), o => { Assert.Equal(6, o.GetAnnotations().Count()); @@ -452,36 +456,37 @@ public virtual void Entities_are_stored_in_model_snapshot() builder.Entity().Ignore(e => e.EntityWithOneProperty); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => { Assert.Equal(2, o.GetEntityTypes().Count()); @@ -504,48 +509,49 @@ public virtual void Entities_are_stored_in_model_snapshot_for_TPT() builder.Entity(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+AbstractBase"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+AbstractBase", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""AbstractBase""); + b.ToTable("AbstractBase"); b.UseTptMappingStrategy(); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity", b => { - b.HasBaseType(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+AbstractBase""); + b.HasBaseType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+AbstractBase"); - b.ToTable(""BaseEntity""); + b.ToTable("BaseEntity"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity", b => { - b.HasBaseType(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity""); + b.HasBaseType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"); - b.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b.Property("Name") + .HasColumnType("nvarchar(max)"); - b.ToTable(""DerivedEntity"", ""foo""); + b.ToTable("DerivedEntity", "foo"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"", null) + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity", null) .WithOne() - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity"", ""Id"") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity", "Id") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - });"), + }); +"""), model => { Assert.Equal(4, model.GetAnnotations().Count()); @@ -573,48 +579,49 @@ public virtual void Entities_are_stored_in_model_snapshot_for_TPT_with_one_exclu builder.Entity(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Discriminator"") + b.Property("Discriminator") .HasMaxLength(13) - .HasColumnType(""nvarchar(13)""); + .HasColumnType("nvarchar(13)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""BaseEntity""); + b.ToTable("BaseEntity"); b.UseTptMappingStrategy(); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity", b => { - b.HasBaseType(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity""); + b.HasBaseType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"); - b.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b.Property("Name") + .HasColumnType("nvarchar(max)"); - b.ToTable(""DerivedEntity"", ""foo"", t => + b.ToTable("DerivedEntity", "foo", t => { t.ExcludeFromMigrations(); }); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"", null) + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity", null) .WithOne() - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity"", ""Id"") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity", "Id") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - });"), + }); +"""), o => { Assert.Equal(4, o.GetAnnotations().Count()); @@ -630,19 +637,20 @@ public void Views_are_stored_in_the_model_snapshot() => Test( builder => builder.Entity().Ignore(e => e.EntityWithTwoProperties).ToView("EntityWithOneProperty"), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") - .HasColumnType(""int""); + b.Property("Id") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); b.ToTable((string)null); - b.ToView(""EntityWithOneProperty"", (string)null); - });"), + b.ToView("EntityWithOneProperty", (string)null); + }); +"""), o => Assert.Equal("EntityWithOneProperty", o.GetEntityTypes().Single().GetViewName())); [ConditionalFact] @@ -652,19 +660,20 @@ public void Views_with_schemas_are_stored_in_the_model_snapshot() .Ignore(e => e.EntityWithTwoProperties) .ToView("EntityWithOneProperty", "ViewSchema"), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") - .HasColumnType(""int""); + b.Property("Id") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); b.ToTable((string)null); - b.ToView(""EntityWithOneProperty"", ""ViewSchema""); - });"), + b.ToView("EntityWithOneProperty", "ViewSchema"); + }); +"""), o => { Assert.Equal("EntityWithOneProperty", o.GetEntityTypes().Single().GetViewName()); @@ -683,44 +692,45 @@ public virtual void Entities_are_stored_in_model_snapshot_for_TPC() builder.Entity().UseTpcMappingStrategy(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.HasSequence(""AbstractBaseSequence""); + GetHeading() + +""" + modelBuilder.HasSequence("AbstractBaseSequence"); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+AbstractBase"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+AbstractBase", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int"") - .HasDefaultValueSql(""NEXT VALUE FOR [AbstractBaseSequence]""); + .HasColumnType("int") + .HasDefaultValueSql("NEXT VALUE FOR [AbstractBaseSequence]"); - SqlServerPropertyBuilderExtensions.UseSequence(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseSequence(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); b.ToTable((string)null); b.UseTpcMappingStrategy(); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity", b => { - b.HasBaseType(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+AbstractBase""); + b.HasBaseType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+AbstractBase"); - b.ToTable(""BaseEntity""); + b.ToTable("BaseEntity"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity", b => { - b.HasBaseType(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity""); + b.HasBaseType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"); - b.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b.Property("Name") + .HasColumnType("nvarchar(max)"); - b.ToTable(""DerivedEntity"", ""foo""); + b.ToTable("DerivedEntity", "foo"); - b.ToView(""DerivedView"", ""foo""); - });"), + b.ToView("DerivedView", "foo"); + }); +"""), model => { Assert.Equal(5, model.GetAnnotations().Count()); @@ -803,155 +813,156 @@ public virtual void Entity_splitting_is_stored_in_snapshot_with_tables() }); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Shadow"") - .HasColumnType(""int"") - .HasColumnName(""Shadow""); + b.Property("Shadow") + .HasColumnType("int") + .HasColumnName("Shadow"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""Order"", null, t => + b.ToTable("Order", null, t => { - t.Property(""Id"") - .HasAnnotation(""fii"", ""arr"") - .HasAnnotation(""SqlServer:IdentityIncrement"", 3) - .HasAnnotation(""SqlServer:IdentitySeed"", 2L) - .HasAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn); + t.Property("Id") + .HasAnnotation("fii", "arr") + .HasAnnotation("SqlServer:IdentityIncrement", 3) + .HasAnnotation("SqlServer:IdentitySeed", 2L) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - t.Property(""Shadow""); + t.Property("Shadow"); }); - b.SplitToTable(""SplitOrder"", null, t => + b.SplitToTable("SplitOrder", null, t => { - t.HasTrigger(""splitTrigger"") - .HasAnnotation(""oof"", ""rab""); + t.HasTrigger("splitTrigger") + .HasAnnotation("oof", "rab"); - t.Property(""Shadow""); + t.Property("Shadow"); - t.HasAnnotation(""foo"", ""bar""); + t.HasAnnotation("foo", "bar"); }); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order"", null) + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order", null) .WithOne() - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order"", ""Id"") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order", "Id") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.OwnsOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails"", ""OrderBillingDetails"", b1 => + b.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails", "OrderBillingDetails", b1 => { - b1.Property(""OrderId"") - .HasColumnType(""int""); + b1.Property("OrderId") + .HasColumnType("int"); - b1.Property(""BillingShadow"") - .HasColumnType(""int""); + b1.Property("BillingShadow") + .HasColumnType("int"); - b1.HasKey(""OrderId""); + b1.HasKey("OrderId"); - b1.ToTable(""SplitOrder"", null, t => + b1.ToTable("SplitOrder", null, t => { - t.Property(""BillingShadow"") - .HasColumnName(""Shadow""); + t.Property("BillingShadow") + .HasColumnName("Shadow"); }); - b1.SplitToTable(""BillingDetails"", null, t => + b1.SplitToTable("BillingDetails", null, t => { - t.Property(""BillingShadow"") - .HasColumnName(""Shadow""); + t.Property("BillingShadow") + .HasColumnName("Shadow"); }); b1.WithOwner() - .HasForeignKey(""OrderId""); + .HasForeignKey("OrderId"); - b1.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order.OrderBillingDetails#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails"", null) + b1.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order.OrderBillingDetails#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails", null) .WithOne() - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order.OrderBillingDetails#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails"", ""OrderId"") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order.OrderBillingDetails#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails", "OrderId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b1.OwnsOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+StreetAddress"", ""StreetAddress"", b2 => + b1.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+StreetAddress", "StreetAddress", b2 => { - b2.Property(""OrderDetailsOrderId"") - .HasColumnType(""int""); + b2.Property("OrderDetailsOrderId") + .HasColumnType("int"); - b2.Property(""City"") - .HasColumnType(""nvarchar(max)""); + b2.Property("City") + .HasColumnType("nvarchar(max)"); - b2.HasKey(""OrderDetailsOrderId""); + b2.HasKey("OrderDetailsOrderId"); - b2.ToTable(""SplitOrder""); + b2.ToTable("SplitOrder"); b2.WithOwner() - .HasForeignKey(""OrderDetailsOrderId""); + .HasForeignKey("OrderDetailsOrderId"); }); - b1.Navigation(""StreetAddress""); + b1.Navigation("StreetAddress"); }); - b.OwnsOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails"", ""OrderShippingDetails"", b1 => + b.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails", "OrderShippingDetails", b1 => { - b1.Property(""OrderId"") - .HasColumnType(""int""); + b1.Property("OrderId") + .HasColumnType("int"); - b1.Property(""ShippingShadow"") - .HasColumnType(""int""); + b1.Property("ShippingShadow") + .HasColumnType("int"); - b1.HasKey(""OrderId""); + b1.HasKey("OrderId"); - b1.ToTable(""Order"", null, t => + b1.ToTable("Order", null, t => { - t.Property(""ShippingShadow"") - .HasColumnName(""Shadow""); + t.Property("ShippingShadow") + .HasColumnName("Shadow"); }); - b1.SplitToTable(""ShippingDetails"", null, t => + b1.SplitToTable("ShippingDetails", null, t => { - t.Property(""ShippingShadow""); + t.Property("ShippingShadow"); }); b1.WithOwner() - .HasForeignKey(""OrderId""); + .HasForeignKey("OrderId"); - b1.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order.OrderShippingDetails#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails"", null) + b1.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order.OrderShippingDetails#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails", null) .WithOne() - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order.OrderShippingDetails#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails"", ""OrderId"") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order.OrderShippingDetails#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails", "OrderId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b1.OwnsOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+StreetAddress"", ""StreetAddress"", b2 => + b1.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+StreetAddress", "StreetAddress", b2 => { - b2.Property(""OrderDetailsOrderId"") - .HasColumnType(""int""); + b2.Property("OrderDetailsOrderId") + .HasColumnType("int"); - b2.Property(""City"") - .HasColumnType(""nvarchar(max)""); + b2.Property("City") + .HasColumnType("nvarchar(max)"); - b2.HasKey(""OrderDetailsOrderId""); + b2.HasKey("OrderDetailsOrderId"); - b2.ToTable(""ShippingDetails"", (string)null); + b2.ToTable("ShippingDetails", (string)null); b2.WithOwner() - .HasForeignKey(""OrderDetailsOrderId""); + .HasForeignKey("OrderDetailsOrderId"); }); - b1.Navigation(""StreetAddress""); + b1.Navigation("StreetAddress"); }); - b.Navigation(""OrderBillingDetails""); + b.Navigation("OrderBillingDetails"); - b.Navigation(""OrderShippingDetails""); - });"), + b.Navigation("OrderShippingDetails"); + }); +"""), model => { Assert.Equal(5, model.GetEntityTypes().Count()); @@ -1068,65 +1079,66 @@ public virtual void Entity_splitting_is_stored_in_snapshot_with_views() }); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") - .HasColumnType(""int""); + b.Property("Id") + .HasColumnType("int"); - b.Property(""Shadow"") - .HasColumnType(""int""); + b.Property("Shadow") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); b.ToTable((string)null); - b.ToView(""EntityWithOneProperty"", null, v => + b.ToView("EntityWithOneProperty", null, v => { - v.Property(""Shadow""); + v.Property("Shadow"); }); - b.SplitToView(""SplitView"", null, v => + b.SplitToView("SplitView", null, v => { - v.Property(""Shadow""); + v.Property("Shadow"); }); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.OwnsOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""EntityWithTwoProperties"", b1 => + b.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "EntityWithTwoProperties", b1 => { - b1.Property(""Id"") - .HasColumnType(""int""); + b1.Property("Id") + .HasColumnType("int"); - b1.Property(""AlternateId"") - .HasColumnType(""int""); + b1.Property("AlternateId") + .HasColumnType("int"); - b1.HasKey(""Id""); + b1.HasKey("Id"); b1.ToTable((string)null); - b1.ToView(""EntityWithOneProperty"", null, v => + b1.ToView("EntityWithOneProperty", null, v => { - v.Property(""AlternateId"") - .HasColumnName(""SomeId""); + v.Property("AlternateId") + .HasColumnName("SomeId"); }); - b1.SplitToView(""SplitView"", null, v => + b1.SplitToView("SplitView", null, v => { - v.Property(""AlternateId"") - .HasColumnName(""SomeOtherId""); + v.Property("AlternateId") + .HasColumnName("SomeOtherId"); }); - b1.WithOwner(""EntityWithOneProperty"") - .HasForeignKey(""Id""); + b1.WithOwner("EntityWithOneProperty") + .HasForeignKey("Id"); - b1.Navigation(""EntityWithOneProperty""); + b1.Navigation("EntityWithOneProperty"); }); - b.Navigation(""EntityWithTwoProperties""); - });"), + b.Navigation("EntityWithTwoProperties"); + }); +"""), model => { var entityWithOneProperty = model.FindEntityType(typeof(EntityWithOneProperty)); @@ -1161,22 +1173,23 @@ public void Unmapped_entity_types_are_stored_in_the_model_snapshot() .UpdateUsingStoredProcedure("Update", "sproc", p => p.HasParameter(e => e.Id)); }, AddBoilerPlate( - @" +""" modelBuilder - .HasDefaultSchema(""default"") - .HasAnnotation(""Relational:MaxIdentifierLength"", 128); + .HasDefaultSchema("default") + .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") - .HasColumnType(""int""); + b.Property("Id") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); b.ToTable((string)null); - });"), + }); +"""), o => { Assert.Null(o.GetEntityTypes().Single().GetTableName()); @@ -1204,15 +1217,16 @@ public void TVF_types_are_stored_in_the_model_snapshot() builder.Entity().HasNoKey().ToTable((string)null); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestKeylessType"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestKeylessType", b => { - b.Property(""Something"") - .HasColumnType(""nvarchar(max)""); + b.Property("Something") + .HasColumnType("nvarchar(max)"); b.ToTable((string)null); - });"), + }); +"""), o => { var entityType = o.GetEntityTypes().Single(); @@ -1231,17 +1245,18 @@ public void Entity_types_mapped_to_functions_are_stored_in_the_model_snapshot() kb.HasNoKey().ToFunction("GetCount"); }), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestKeylessType"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestKeylessType", b => { - b.Property(""Something"") - .HasColumnType(""nvarchar(max)""); + b.Property("Something") + .HasColumnType("nvarchar(max)"); b.ToTable((string)null); - b.ToFunction(""GetCount""); - });"), + b.ToFunction("GetCount"); + }); +"""), o => Assert.Equal("GetCount", o.GetEntityTypes().Single().GetFunctionName())); [ConditionalFact] @@ -1249,19 +1264,20 @@ public void Entity_types_mapped_to_queries_are_stored_in_the_model_snapshot() => Test( builder => builder.Entity().Ignore(e => e.EntityWithTwoProperties).ToSqlQuery("query"), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") - .HasColumnType(""int""); + b.Property("Id") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); b.ToTable((string)null); - b.ToSqlQuery(""query""); - });"), + b.ToSqlQuery("query"); + }); +"""), o => Assert.Equal("query", o.GetEntityTypes().Single().GetSqlQuery())); [ConditionalFact] @@ -1278,15 +1294,16 @@ public virtual void Sequence_is_stored_in_snapshot_as_fluent_api() .HasAnnotation("foo", "bar"); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.HasSequence(""Foo"", ""Bar"") + GetHeading() + +""" + modelBuilder.HasSequence("Foo", "Bar") .StartsAt(2L) .IncrementsBy(2) .HasMin(1L) .HasMax(3L) .IsCyclic() - .HasAnnotation(""foo"", ""bar"");"), + .HasAnnotation("foo", "bar"); +"""), model => { Assert.Equal(5, model.GetAnnotations().Count()); @@ -1307,28 +1324,29 @@ public virtual void HiLoSequence_with_default_model_schema() .HasDefaultSchema("dbo") .Entity("Entity").Property("Id").UseHiLo(schema: "dbo"), AddBoilerPlate( - @" +""" modelBuilder - .HasDefaultSchema(""dbo"") - .HasAnnotation(""Relational:MaxIdentifierLength"", 128); + .HasDefaultSchema("dbo") + .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.HasSequence(""EntityFrameworkHiLoSequence"", ""dbo"") + modelBuilder.HasSequence("EntityFrameworkHiLoSequence", "dbo") .IncrementsBy(10); - modelBuilder.Entity(""Entity"", b => + modelBuilder.Entity("Entity", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseHiLo(b.Property(""Id""), ""EntityFrameworkHiLoSequence"", ""dbo""); + SqlServerPropertyBuilderExtensions.UseHiLo(b.Property("Id"), "EntityFrameworkHiLoSequence", "dbo"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""Entity"", ""dbo""); - });"), + b.ToTable("Entity", "dbo"); + }); +"""), model => { Assert.Equal("dbo", model.GetDefaultSchema()); @@ -1350,28 +1368,29 @@ public virtual void CheckConstraint_is_stored_in_snapshot_as_fluent_api() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties"", t => + b.ToTable("EntityWithTwoProperties", t => { - t.HasCheckConstraint(""AlternateId"", ""AlternateId > Id"") - .HasName(""CK_Customer_AlternateId"") - .HasAnnotation(""foo"", ""bar""); + t.HasCheckConstraint("AlternateId", "AlternateId > Id") + .HasName("CK_Customer_AlternateId") + .HasAnnotation("foo", "bar"); }); - });"), + }); +"""), o => { var constraint = o.GetEntityTypes().Single().GetCheckConstraints().Single(); @@ -1389,44 +1408,45 @@ public virtual void CheckConstraint_is_only_stored_in_snapshot_once_for_TPH() builder.Entity(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Discriminator"") + b.Property("Discriminator") .IsRequired() .HasMaxLength(13) - .HasColumnType(""nvarchar(13)""); + .HasColumnType("nvarchar(13)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""BaseEntity""); + b.ToTable("BaseEntity"); - b.HasDiscriminator(""Discriminator"").HasValue(""BaseEntity""); + b.HasDiscriminator("Discriminator").HasValue("BaseEntity"); b.UseTphMappingStrategy(); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity", b => { - b.HasBaseType(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity""); + b.HasBaseType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"); - b.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b.Property("Name") + .HasColumnType("nvarchar(max)"); b.ToTable(t => { - t.HasCheckConstraint(""CK_BaseEntity_AlternateId"", ""AlternateId > Id""); + t.HasCheckConstraint("CK_BaseEntity_AlternateId", "AlternateId > Id"); }); - b.HasDiscriminator().HasValue(""DerivedEntity""); - });"), + b.HasDiscriminator().HasValue("DerivedEntity"); + }); +"""), o => { var constraint = o.FindEntityType(typeof(DerivedEntity)).GetDeclaredCheckConstraints().Single(); @@ -1443,25 +1463,26 @@ public virtual void Trigger_is_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty"", t => + b.ToTable("EntityWithOneProperty", t => { - t.HasTrigger(""SomeTrigger"") - .HasDatabaseName(""SomeTrg"") - .HasAnnotation(""foo"", ""bar""); + t.HasTrigger("SomeTrigger") + .HasDatabaseName("SomeTrg") + .HasAnnotation("foo", "bar"); }); - });"), + }); +"""), o => { var trigger = Assert.Single(o.GetEntityTypes().Single().GetDeclaredTriggers()); @@ -1485,27 +1506,28 @@ public virtual void Triggers_and_ExcludeFromMigrations_are_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty"", t => + b.ToTable("EntityWithOneProperty", t => { t.ExcludeFromMigrations(); - t.HasTrigger(""SomeTrigger1""); + t.HasTrigger("SomeTrigger1"); - t.HasTrigger(""SomeTrigger2""); + t.HasTrigger("SomeTrigger2"); }); - });"), + }); +"""), o => { var entityType = Assert.Single(o.GetEntityTypes()); @@ -1535,10 +1557,11 @@ public virtual void Model_use_identity_columns() => Test( builder => builder.UseIdentityColumns(), AddBoilerPlate( - @" - modelBuilder.HasAnnotation(""Relational:MaxIdentifierLength"", 128); +""" + modelBuilder.HasAnnotation("Relational:MaxIdentifierLength", 128); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);"), + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); +"""), o => { Assert.Equal(4, o.GetAnnotations().Count()); @@ -1552,10 +1575,11 @@ public virtual void Model_use_identity_columns_custom_seed() => Test( builder => builder.UseIdentityColumns(5), AddBoilerPlate( - @" - modelBuilder.HasAnnotation(""Relational:MaxIdentifierLength"", 128); +""" + modelBuilder.HasAnnotation("Relational:MaxIdentifierLength", 128); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 5L);"), + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 5L); +"""), o => { Assert.Equal(4, o.GetAnnotations().Count()); @@ -1569,10 +1593,11 @@ public virtual void Model_use_identity_columns_custom_increment() => Test( builder => builder.UseIdentityColumns(increment: 5), AddBoilerPlate( - @" - modelBuilder.HasAnnotation(""Relational:MaxIdentifierLength"", 128); +""" + modelBuilder.HasAnnotation("Relational:MaxIdentifierLength", 128); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 5);"), + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 5); +"""), o => { Assert.Equal(4, o.GetAnnotations().Count()); @@ -1598,23 +1623,24 @@ public virtual void Model_use_identity_columns_custom_seed_increment() }); }, AddBoilerPlate( - @" - modelBuilder.HasAnnotation(""Relational:MaxIdentifierLength"", 128); +""" + modelBuilder.HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 9223372036854775807L, 5); - modelBuilder.Entity(""Building"", b => + modelBuilder.Entity("Building", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id""), 9223372036854775807L, 5); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 9223372036854775807L, 5); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""Buildings"", (string)null); - });"), + b.ToTable("Buildings", (string)null); + }); +"""), o => { Assert.Equal(4, o.GetAnnotations().Count()); @@ -1641,22 +1667,23 @@ public virtual void EntityType_annotations_are_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); - b.HasAnnotation(""AnnotationName"", ""AnnotationValue""); - });"), + b.HasAnnotation("AnnotationName", "AnnotationValue"); + }); +"""), o => { Assert.Equal(3, o.GetEntityTypes().First().GetAnnotations().Count()); @@ -1672,24 +1699,25 @@ public virtual void EntityType_Fluent_APIs_are_properly_generated() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - SqlServerKeyBuilderExtensions.IsClustered(b.HasKey(""Id""), false); + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("Id"), false); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); SqlServerEntityTypeBuilderExtensions.IsMemoryOptimized(b); - });"), + }); +"""), o => Assert.True(o.GetEntityTypes().Single().IsMemoryOptimized())); [ConditionalFact] @@ -1701,49 +1729,50 @@ public virtual void BaseType_is_stored_in_snapshot() builder.Entity().HasBaseType(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Discriminator"") + b.Property("Discriminator") .IsRequired() .HasMaxLength(21) - .HasColumnType(""nvarchar(21)""); + .HasColumnType("nvarchar(21)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""BaseEntity""); + b.ToTable("BaseEntity"); - b.HasDiscriminator(""Discriminator"").HasValue(""BaseEntity""); + b.HasDiscriminator("Discriminator").HasValue("BaseEntity"); b.UseTphMappingStrategy(); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+AnotherDerivedEntity"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+AnotherDerivedEntity", b => { - b.HasBaseType(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity""); + b.HasBaseType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"); - b.Property(""Title"") - .HasColumnType(""nvarchar(max)""); + b.Property("Title") + .HasColumnType("nvarchar(max)"); - b.HasDiscriminator().HasValue(""AnotherDerivedEntity""); + b.HasDiscriminator().HasValue("AnotherDerivedEntity"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity", b => { - b.HasBaseType(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity""); + b.HasBaseType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"); - b.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b.Property("Name") + .HasColumnType("nvarchar(max)"); - b.HasDiscriminator().HasValue(""DerivedEntity""); - });"), + b.HasDiscriminator().HasValue("DerivedEntity"); + }); +"""), o => { Assert.Equal(3, o.GetEntityTypes().Count()); @@ -1771,49 +1800,50 @@ public virtual void Discriminator_annotations_are_stored_in_snapshot() .HasValue(typeof(AnotherDerivedEntity), typeof(AnotherDerivedEntity).Name); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Discriminator"") + b.Property("Discriminator") .IsRequired() .HasMaxLength(21) - .HasColumnType(""nvarchar(21)""); + .HasColumnType("nvarchar(21)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""BaseEntity""); + b.ToTable("BaseEntity"); - b.HasDiscriminator(""Discriminator"").IsComplete(true).HasValue(""BaseEntity""); + b.HasDiscriminator("Discriminator").IsComplete(true).HasValue("BaseEntity"); b.UseTphMappingStrategy(); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+AnotherDerivedEntity"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+AnotherDerivedEntity", b => { - b.HasBaseType(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity""); + b.HasBaseType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"); - b.Property(""Title"") - .HasColumnType(""nvarchar(max)""); + b.Property("Title") + .HasColumnType("nvarchar(max)"); - b.HasDiscriminator().HasValue(""AnotherDerivedEntity""); + b.HasDiscriminator().HasValue("AnotherDerivedEntity"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity", b => { - b.HasBaseType(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity""); + b.HasBaseType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"); - b.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b.Property("Name") + .HasColumnType("nvarchar(max)"); - b.HasDiscriminator().HasValue(""DerivedEntity""); - });"), + b.HasDiscriminator().HasValue("DerivedEntity"); + }); +"""), o => { Assert.Equal("Discriminator", o.FindEntityType(typeof(BaseEntity))[CoreAnnotationNames.DiscriminatorProperty]); @@ -1847,48 +1877,49 @@ public virtual void Converted_discriminator_annotations_are_stored_in_snapshot() }); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntityWithStructDiscriminator"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntityWithStructDiscriminator", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Discriminator"") + b.Property("Discriminator") .IsRequired() - .HasColumnType(""nvarchar(max)""); + .HasColumnType("nvarchar(max)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""BaseEntityWithStructDiscriminator""); + b.ToTable("BaseEntityWithStructDiscriminator"); - b.HasDiscriminator(""Discriminator"").IsComplete(true).HasValue(""Base""); + b.HasDiscriminator("Discriminator").IsComplete(true).HasValue("Base"); b.UseTphMappingStrategy(); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+AnotherDerivedEntityWithStructDiscriminator"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+AnotherDerivedEntityWithStructDiscriminator", b => { - b.HasBaseType(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntityWithStructDiscriminator""); + b.HasBaseType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntityWithStructDiscriminator"); - b.Property(""Title"") - .HasColumnType(""nvarchar(max)""); + b.Property("Title") + .HasColumnType("nvarchar(max)"); - b.HasDiscriminator().HasValue(""Another""); + b.HasDiscriminator().HasValue("Another"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntityWithStructDiscriminator"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntityWithStructDiscriminator", b => { - b.HasBaseType(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntityWithStructDiscriminator""); + b.HasBaseType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntityWithStructDiscriminator"); - b.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b.Property("Name") + .HasColumnType("nvarchar(max)"); - b.HasDiscriminator().HasValue(""Derived""); - });"), + b.HasDiscriminator().HasValue("Derived"); + }); +"""), o => { Assert.Equal( @@ -1917,23 +1948,24 @@ public virtual void Properties_are_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => { Assert.Equal(2, o.GetEntityTypes().First().GetProperties().Count()); @@ -1954,20 +1986,21 @@ public virtual void Primary_key_is_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") - .HasColumnType(""int""); + b.Property("Id") + .HasColumnType("int"); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id"", ""AlternateId""); + b.HasKey("Id", "AlternateId"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => { Assert.Equal(2, o.GetEntityTypes().First().FindPrimaryKey().Properties.Count); @@ -1983,15 +2016,16 @@ public void HasNoKey_is_handled() => Test( builder => builder.Entity().Ignore(e => e.EntityWithTwoProperties).HasNoKey(), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") - .HasColumnType(""int""); + b.Property("Id") + .HasColumnType("int"); - b.ToTable(""EntityWithOneProperty""); - });"), + b.ToTable("EntityWithOneProperty"); + }); +"""), o => { var entityType = Assert.Single(o.GetEntityTypes()); @@ -2010,25 +2044,26 @@ public virtual void Alternate_keys_are_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasAlternateKey(""Id"", ""AlternateId""); + b.HasAlternateKey("Id", "AlternateId"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => { Assert.Collection( @@ -2047,25 +2082,26 @@ public virtual void Indexes_are_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""AlternateId""); + b.HasIndex("AlternateId"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => { Assert.Single(o.GetEntityTypes().First().GetIndexes()); @@ -2082,25 +2118,26 @@ public virtual void Indexes_are_stored_in_snapshot_including_composite_index() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""Id"", ""AlternateId""); + b.HasIndex("Id", "AlternateId"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => { Assert.Single(o.GetEntityTypes().First().GetIndexes()); @@ -2122,55 +2159,56 @@ public virtual void Foreign_keys_are_stored_in_snapshot() .HasForeignKey(e => e.AlternateId); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""AlternateId"") + b.HasIndex("AlternateId") .IsUnique(); - b.ToTable(""EntityWithTwoProperties""); + b.ToTable("EntityWithTwoProperties"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", ""EntityWithOneProperty"") - .WithOne(""EntityWithTwoProperties"") - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""AlternateId"") + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", "EntityWithOneProperty") + .WithOne("EntityWithTwoProperties") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "AlternateId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation(""EntityWithOneProperty""); + b.Navigation("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Navigation(""EntityWithTwoProperties""); - });"), + b.Navigation("EntityWithTwoProperties"); + }); +"""), o => { var foreignKey = o.FindEntityType(typeof(EntityWithTwoProperties)).GetForeignKeys().Single(); @@ -2195,69 +2233,70 @@ public virtual void Many_to_many_join_table_stored_in_snapshot() .ToTable("ManyToManyRight", "schema"); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""ManyToManyLeftManyToManyRight"", b => + GetHeading() + +""" + modelBuilder.Entity("ManyToManyLeftManyToManyRight", b => { - b.Property(""LeftsId"") - .HasColumnType(""int""); + b.Property("LeftsId") + .HasColumnType("int"); - b.Property(""RightsId"") - .HasColumnType(""int""); + b.Property("RightsId") + .HasColumnType("int"); - b.HasKey(""LeftsId"", ""RightsId""); + b.HasKey("LeftsId", "RightsId"); - b.HasIndex(""RightsId""); + b.HasIndex("RightsId"); - b.ToTable(""ManyToManyLeftManyToManyRight"", ""schema""); + b.ToTable("ManyToManyLeftManyToManyRight", "schema"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyLeft"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyLeft", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b.Property("Name") + .HasColumnType("nvarchar(max)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""ManyToManyLeft"", ""schema""); + b.ToTable("ManyToManyLeft", "schema"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyRight"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyRight", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Description"") - .HasColumnType(""nvarchar(max)""); + b.Property("Description") + .HasColumnType("nvarchar(max)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""ManyToManyRight"", ""schema""); + b.ToTable("ManyToManyRight", "schema"); }); - modelBuilder.Entity(""ManyToManyLeftManyToManyRight"", b => + modelBuilder.Entity("ManyToManyLeftManyToManyRight", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyLeft"", null) + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyLeft", null) .WithMany() - .HasForeignKey(""LeftsId"") + .HasForeignKey("LeftsId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyRight"", null) + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyRight", null) .WithMany() - .HasForeignKey(""RightsId"") + .HasForeignKey("RightsId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - });"), + }); +"""), model => { var joinEntity = model.FindEntityType("ManyToManyLeftManyToManyRight"); @@ -2339,69 +2378,70 @@ public virtual void Can_override_table_name_for_many_to_many_join_table_stored_i .UsingEntity(a => a.ToTable("MyJoinTable")); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""ManyToManyLeftManyToManyRight"", b => + GetHeading() + +""" + modelBuilder.Entity("ManyToManyLeftManyToManyRight", b => { - b.Property(""LeftsId"") - .HasColumnType(""int""); + b.Property("LeftsId") + .HasColumnType("int"); - b.Property(""RightsId"") - .HasColumnType(""int""); + b.Property("RightsId") + .HasColumnType("int"); - b.HasKey(""LeftsId"", ""RightsId""); + b.HasKey("LeftsId", "RightsId"); - b.HasIndex(""RightsId""); + b.HasIndex("RightsId"); - b.ToTable(""MyJoinTable"", (string)null); + b.ToTable("MyJoinTable", (string)null); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyLeft"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyLeft", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b.Property("Name") + .HasColumnType("nvarchar(max)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""ManyToManyLeft""); + b.ToTable("ManyToManyLeft"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyRight"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyRight", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Description"") - .HasColumnType(""nvarchar(max)""); + b.Property("Description") + .HasColumnType("nvarchar(max)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""ManyToManyRight""); + b.ToTable("ManyToManyRight"); }); - modelBuilder.Entity(""ManyToManyLeftManyToManyRight"", b => + modelBuilder.Entity("ManyToManyLeftManyToManyRight", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyLeft"", null) + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyLeft", null) .WithMany() - .HasForeignKey(""LeftsId"") + .HasForeignKey("LeftsId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyRight"", null) + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+ManyToManyRight", null) .WithMany() - .HasForeignKey(""RightsId"") + .HasForeignKey("RightsId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - });"), + }); +"""), model => { var joinEntity = model.FindEntityType("ManyToManyLeftManyToManyRight"); @@ -2484,18 +2524,19 @@ public virtual void TableName_preserved_when_generic() originalModel = builder.Model; }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithGenericKey"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithGenericKey", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""uniqueidentifier""); + .HasColumnType("uniqueidentifier"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithGenericKey""); - });", usingSystem: true), + b.ToTable("EntityWithGenericKey"); + }); +""", usingSystem: true), model => { var originalEntity = originalModel.FindEntityType(typeof(EntityWithGenericKey)); @@ -2527,56 +2568,57 @@ public virtual void Shared_columns_are_stored_in_the_snapshot() }); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") + b.Property("AlternateId") .ValueGeneratedOnUpdateSometimes() - .HasColumnType(""int"") - .HasColumnName(""AlternateId""); + .HasColumnType("int") + .HasColumnName("AlternateId"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithProperties"", (string)null); + b.ToTable("EntityWithProperties", (string)null); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") - .HasColumnType(""int""); + b.Property("Id") + .HasColumnType("int"); - b.Property(""AlternateId"") + b.Property("AlternateId") .ValueGeneratedOnUpdateSometimes() - .HasColumnType(""int"") - .HasColumnName(""AlternateId""); + .HasColumnType("int") + .HasColumnName("AlternateId"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithProperties"", (string)null); + b.ToTable("EntityWithProperties", (string)null); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", ""EntityWithOneProperty"") - .WithOne(""EntityWithTwoProperties"") - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""Id"") + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", "EntityWithOneProperty") + .WithOne("EntityWithTwoProperties") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "Id") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation(""EntityWithOneProperty""); + b.Navigation("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Navigation(""EntityWithTwoProperties""); - });", usingSystem: false), + b.Navigation("EntityWithTwoProperties"); + }); +""", usingSystem: false), model => { var entityType = model.FindEntityType(typeof(EntityWithOneProperty)); @@ -2597,18 +2639,19 @@ public virtual void PrimaryKey_name_preserved_when_generic() originalModel = builder.Model; }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithGenericKey"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithGenericKey", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""uniqueidentifier""); + .HasColumnType("uniqueidentifier"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithGenericKey""); - });", usingSystem: true), + b.ToTable("EntityWithGenericKey"); + }); +""", usingSystem: true), model => { var originalEntity = originalModel.FindEntityType(typeof(EntityWithGenericKey)); @@ -2635,25 +2678,26 @@ public virtual void AlternateKey_name_preserved_when_generic() originalModel = builder.Model; }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithGenericProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithGenericProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Property"") - .HasColumnType(""uniqueidentifier""); + b.Property("Property") + .HasColumnType("uniqueidentifier"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasAlternateKey(""Property""); + b.HasAlternateKey("Property"); - b.ToTable(""EntityWithGenericProperty""); - });", usingSystem: true), + b.ToTable("EntityWithGenericProperty"); + }); +""", usingSystem: true), model => { var originalEntity = originalModel.FindEntityType(typeof(EntityWithGenericProperty)); @@ -2672,25 +2716,26 @@ public virtual void Discriminator_of_enum() => Test( builder => builder.Entity().HasDiscriminator(e => e.Day), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithEnumType"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithEnumType", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Day"") - .HasColumnType(""bigint""); + b.Property("Day") + .HasColumnType("bigint"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithEnumType""); + b.ToTable("EntityWithEnumType"); - b.HasDiscriminator(""Day""); - });"), + b.HasDiscriminator("Day"); + }); +"""), model => Assert.Equal(typeof(long), model.GetEntityTypes().First().FindDiscriminatorProperty().ClrType)); [ConditionalFact] @@ -2703,26 +2748,27 @@ public virtual void Discriminator_of_enum_to_string() x.HasDiscriminator(e => e.Day); }), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithEnumType"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithEnumType", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Day"") + b.Property("Day") .IsRequired() - .HasColumnType(""nvarchar(max)""); + .HasColumnType("nvarchar(max)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithEnumType""); + b.ToTable("EntityWithEnumType"); - b.HasDiscriminator(""Day""); - });"), + b.HasDiscriminator("Day"); + }); +"""), model => { var discriminatorProperty = model.GetEntityTypes().First().FindDiscriminatorProperty(); @@ -2742,44 +2788,45 @@ public virtual void Temporal_table_information_is_stored_in_snapshot() ttb.HasPeriodEnd("End").HasColumnName("PeriodEnd"); })), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""End"") + b.Property("End") .ValueGeneratedOnAddOrUpdate() - .HasColumnType(""datetime2"") - .HasColumnName(""PeriodEnd""); + .HasColumnType("datetime2") + .HasColumnName("PeriodEnd"); - b.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b.Property("Name") + .HasColumnType("nvarchar(max)"); - b.Property(""Start"") + b.Property("Start") .ValueGeneratedOnAddOrUpdate() - .HasColumnType(""datetime2"") - .HasColumnName(""PeriodStart""); + .HasColumnType("datetime2") + .HasColumnName("PeriodStart"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithStringProperty""); + b.ToTable("EntityWithStringProperty"); b.ToTable(tb => tb.IsTemporal(ttb => { - ttb.UseHistoryTable(""HistoryTable""); + ttb.UseHistoryTable("HistoryTable"); ttb - .HasPeriodStart(""Start"") - .HasColumnName(""PeriodStart""); + .HasPeriodStart("Start") + .HasColumnName("PeriodStart"); ttb - .HasPeriodEnd(""End"") - .HasColumnName(""PeriodEnd""); + .HasPeriodEnd("End") + .HasColumnName("PeriodEnd"); })); - });", usingSystem: true), + }); +""", usingSystem: true), o => { var temporalEntity = o.FindEntityType( @@ -2803,44 +2850,45 @@ public virtual void Temporal_table_information_is_stored_in_snapshot_minimal_set => Test( builder => builder.Entity().ToTable(tb => tb.IsTemporal()), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b.Property("Name") + .HasColumnType("nvarchar(max)"); - b.Property(""PeriodEnd"") + b.Property("PeriodEnd") .ValueGeneratedOnAddOrUpdate() - .HasColumnType(""datetime2"") - .HasColumnName(""PeriodEnd""); + .HasColumnType("datetime2") + .HasColumnName("PeriodEnd"); - b.Property(""PeriodStart"") + b.Property("PeriodStart") .ValueGeneratedOnAddOrUpdate() - .HasColumnType(""datetime2"") - .HasColumnName(""PeriodStart""); + .HasColumnType("datetime2") + .HasColumnName("PeriodStart"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithStringProperty""); + b.ToTable("EntityWithStringProperty"); b.ToTable(tb => tb.IsTemporal(ttb => { - ttb.UseHistoryTable(""EntityWithStringPropertyHistory""); + ttb.UseHistoryTable("EntityWithStringPropertyHistory"); ttb - .HasPeriodStart(""PeriodStart"") - .HasColumnName(""PeriodStart""); + .HasPeriodStart("PeriodStart") + .HasColumnName("PeriodStart"); ttb - .HasPeriodEnd(""PeriodEnd"") - .HasColumnName(""PeriodEnd""); + .HasPeriodEnd("PeriodEnd") + .HasColumnName("PeriodEnd"); })); - });", usingSystem: true), + }); +""", usingSystem: true), o => { var temporalEntity = o.FindEntityType( @@ -2900,20 +2948,20 @@ public virtual void Owned_types_are_stored_in_snapshot() })); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id"") - .HasName(""PK_Custom""); + b.HasKey("Id") + .HasName("PK_Custom"); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); b.HasData( new @@ -2922,53 +2970,53 @@ public virtual void Owned_types_are_stored_in_snapshot() }); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey", b => { - b.Property(""Id"") - .HasColumnType(""nvarchar(450)""); + b.Property("Id") + .HasColumnType("nvarchar(450)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithStringKey""); + b.ToTable("EntityWithStringKey"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.OwnsOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""EntityWithTwoProperties"", b1 => + b.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "EntityWithTwoProperties", b1 => { - b1.Property(""AlternateId"") - .HasColumnType(""int""); + b1.Property("AlternateId") + .HasColumnType("int"); - b1.Property(""EntityWithStringKeyId"") - .HasColumnType(""nvarchar(450)""); + b1.Property("EntityWithStringKeyId") + .HasColumnType("nvarchar(450)"); - b1.Property(""Id"") - .HasColumnType(""int""); + b1.Property("Id") + .HasColumnType("int"); - b1.HasKey(""AlternateId"") - .HasName(""PK_Custom""); + b1.HasKey("AlternateId") + .HasName("PK_Custom"); - b1.HasIndex(""EntityWithStringKeyId"") + b1.HasIndex("EntityWithStringKeyId") .IsUnique() - .HasFilter(""[EntityWithTwoProperties_EntityWithStringKeyId] IS NOT NULL""); + .HasFilter("[EntityWithTwoProperties_EntityWithStringKeyId] IS NOT NULL"); - b1.HasIndex(""Id""); + b1.HasIndex("Id"); - SqlServerIndexBuilderExtensions.IncludeProperties(b1.HasIndex(""Id""), new[] { ""AlternateId"" }); + SqlServerIndexBuilderExtensions.IncludeProperties(b1.HasIndex("Id"), new[] { "AlternateId" }); - b1.ToTable(""EntityWithOneProperty""); + b1.ToTable("EntityWithOneProperty"); - b1.WithOwner(""EntityWithOneProperty"") - .HasForeignKey(""AlternateId"") - .HasConstraintName(""FK_Custom""); + b1.WithOwner("EntityWithOneProperty") + .HasForeignKey("AlternateId") + .HasConstraintName("FK_Custom"); - b1.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey"", ""EntityWithStringKey"") + b1.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey", "EntityWithStringKey") .WithOne() - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty.EntityWithTwoProperties#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""EntityWithStringKeyId""); + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty.EntityWithTwoProperties#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "EntityWithStringKeyId"); - b1.Navigation(""EntityWithOneProperty""); + b1.Navigation("EntityWithOneProperty"); - b1.Navigation(""EntityWithStringKey""); + b1.Navigation("EntityWithStringKey"); b1.HasData( new @@ -2978,51 +3026,52 @@ public virtual void Owned_types_are_stored_in_snapshot() }); }); - b.Navigation(""EntityWithTwoProperties""); + b.Navigation("EntityWithTwoProperties"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey", b => { - b.OwnsMany(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", ""Properties"", b1 => + b.OwnsMany("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", "Properties", b1 => { - b1.Property(""Id"") + b1.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b1.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b1.Property("Id")); - b1.Property(""EntityWithOnePropertyId"") - .HasColumnType(""int""); + b1.Property("EntityWithOnePropertyId") + .HasColumnType("int"); - b1.Property(""EntityWithStringKeyId"") + b1.Property("EntityWithStringKeyId") .IsRequired() - .HasColumnType(""nvarchar(450)""); + .HasColumnType("nvarchar(450)"); - b1.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b1.Property("Name") + .HasColumnType("nvarchar(max)"); - b1.HasKey(""Id""); + b1.HasKey("Id"); - b1.HasIndex(""EntityWithOnePropertyId"") + b1.HasIndex("EntityWithOnePropertyId") .IsUnique() - .HasFilter(""[EntityWithOnePropertyId] IS NOT NULL""); + .HasFilter("[EntityWithOnePropertyId] IS NOT NULL"); - b1.HasIndex(""EntityWithStringKeyId""); + b1.HasIndex("EntityWithStringKeyId"); - b1.ToTable(""EntityWithStringProperty""); + b1.ToTable("EntityWithStringProperty"); - b1.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", ""EntityWithOneProperty"") + b1.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", "EntityWithOneProperty") .WithOne() - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey.Properties#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", ""EntityWithOnePropertyId""); + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey.Properties#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", "EntityWithOnePropertyId"); b1.WithOwner() - .HasForeignKey(""EntityWithStringKeyId""); + .HasForeignKey("EntityWithStringKeyId"); - b1.Navigation(""EntityWithOneProperty""); + b1.Navigation("EntityWithOneProperty"); }); - b.Navigation(""Properties""); - });", usingSystem: true), + b.Navigation("Properties"); + }); +""", usingSystem: true), o => { var entityWithOneProperty = o.FindEntityType(typeof(EntityWithOneProperty)); @@ -3128,20 +3177,20 @@ public virtual void Owned_types_are_stored_in_snapshot_when_excluded() }); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id"") - .HasName(""PK_Custom""); + b.HasKey("Id") + .HasName("PK_Custom"); - b.ToTable(""EntityWithOneProperty"", null, t => + b.ToTable("EntityWithOneProperty", null, t => { t.ExcludeFromMigrations(); }); @@ -3153,54 +3202,54 @@ public virtual void Owned_types_are_stored_in_snapshot_when_excluded() }); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey", b => { - b.Property(""Id"") - .HasColumnType(""nvarchar(450)""); + b.Property("Id") + .HasColumnType("nvarchar(450)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithStringKey"", null, t => + b.ToTable("EntityWithStringKey", null, t => { t.ExcludeFromMigrations(); }); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.OwnsOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""EntityWithTwoProperties"", b1 => + b.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "EntityWithTwoProperties", b1 => { - b1.Property(""AlternateId"") - .HasColumnType(""int""); + b1.Property("AlternateId") + .HasColumnType("int"); - b1.Property(""EntityWithStringKeyId"") - .HasColumnType(""nvarchar(450)""); + b1.Property("EntityWithStringKeyId") + .HasColumnType("nvarchar(450)"); - b1.Property(""Id"") - .HasColumnType(""int""); + b1.Property("Id") + .HasColumnType("int"); - b1.HasKey(""AlternateId"") - .HasName(""PK_Custom""); + b1.HasKey("AlternateId") + .HasName("PK_Custom"); - b1.HasIndex(""EntityWithStringKeyId"") + b1.HasIndex("EntityWithStringKeyId") .IsUnique() - .HasFilter(""[EntityWithTwoProperties_EntityWithStringKeyId] IS NOT NULL""); + .HasFilter("[EntityWithTwoProperties_EntityWithStringKeyId] IS NOT NULL"); - b1.HasIndex(""Id""); + b1.HasIndex("Id"); - b1.ToTable(""EntityWithOneProperty""); + b1.ToTable("EntityWithOneProperty"); - b1.WithOwner(""EntityWithOneProperty"") - .HasForeignKey(""AlternateId"") - .HasConstraintName(""FK_Custom""); + b1.WithOwner("EntityWithOneProperty") + .HasForeignKey("AlternateId") + .HasConstraintName("FK_Custom"); - b1.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey"", ""EntityWithStringKey"") + b1.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey", "EntityWithStringKey") .WithOne() - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty.EntityWithTwoProperties#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""EntityWithStringKeyId""); + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty.EntityWithTwoProperties#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "EntityWithStringKeyId"); - b1.Navigation(""EntityWithOneProperty""); + b1.Navigation("EntityWithOneProperty"); - b1.Navigation(""EntityWithStringKey""); + b1.Navigation("EntityWithStringKey"); b1.HasData( new @@ -3210,54 +3259,55 @@ public virtual void Owned_types_are_stored_in_snapshot_when_excluded() }); }); - b.Navigation(""EntityWithTwoProperties""); + b.Navigation("EntityWithTwoProperties"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey", b => { - b.OwnsMany(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", ""Properties"", b1 => + b.OwnsMany("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", "Properties", b1 => { - b1.Property(""Id"") + b1.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b1.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b1.Property("Id")); - b1.Property(""EntityWithOnePropertyId"") - .HasColumnType(""int""); + b1.Property("EntityWithOnePropertyId") + .HasColumnType("int"); - b1.Property(""EntityWithStringKeyId"") + b1.Property("EntityWithStringKeyId") .IsRequired() - .HasColumnType(""nvarchar(450)""); + .HasColumnType("nvarchar(450)"); - b1.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b1.Property("Name") + .HasColumnType("nvarchar(max)"); - b1.HasKey(""Id""); + b1.HasKey("Id"); - b1.HasIndex(""EntityWithOnePropertyId"") + b1.HasIndex("EntityWithOnePropertyId") .IsUnique() - .HasFilter(""[EntityWithOnePropertyId] IS NOT NULL""); + .HasFilter("[EntityWithOnePropertyId] IS NOT NULL"); - b1.HasIndex(""EntityWithStringKeyId""); + b1.HasIndex("EntityWithStringKeyId"); - b1.ToTable(""EntityWithStringProperty"", null, t => + b1.ToTable("EntityWithStringProperty", null, t => { t.ExcludeFromMigrations(); }); - b1.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", ""EntityWithOneProperty"") + b1.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", "EntityWithOneProperty") .WithOne() - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey.Properties#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", ""EntityWithOnePropertyId""); + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey.Properties#Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", "EntityWithOnePropertyId"); b1.WithOwner() - .HasForeignKey(""EntityWithStringKeyId""); + .HasForeignKey("EntityWithStringKeyId"); - b1.Navigation(""EntityWithOneProperty""); + b1.Navigation("EntityWithOneProperty"); }); - b.Navigation(""Properties""); - });", usingSystem: true), + b.Navigation("Properties"); + }); +""", usingSystem: true), o => { var entityWithOneProperty = o.FindEntityType(typeof(EntityWithOneProperty)); @@ -3325,122 +3375,123 @@ public virtual void Shared_owned_types_are_stored_in_snapshot() builder.Entity().OwnsOne(p => p.OrderInfo, od => od.OwnsOne(c => c.StreetAddress)); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""Order""); + b.ToTable("Order"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order", b => { - b.OwnsOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails"", ""OrderBillingDetails"", b1 => + b.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails", "OrderBillingDetails", b1 => { - b1.Property(""OrderId"") - .HasColumnType(""int""); + b1.Property("OrderId") + .HasColumnType("int"); - b1.HasKey(""OrderId""); + b1.HasKey("OrderId"); - b1.ToTable(""Order""); + b1.ToTable("Order"); b1.WithOwner() - .HasForeignKey(""OrderId""); + .HasForeignKey("OrderId"); - b1.OwnsOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+StreetAddress"", ""StreetAddress"", b2 => + b1.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+StreetAddress", "StreetAddress", b2 => { - b2.Property(""OrderDetailsOrderId"") - .HasColumnType(""int""); + b2.Property("OrderDetailsOrderId") + .HasColumnType("int"); - b2.Property(""City"") - .HasColumnType(""nvarchar(max)""); + b2.Property("City") + .HasColumnType("nvarchar(max)"); - b2.HasKey(""OrderDetailsOrderId""); + b2.HasKey("OrderDetailsOrderId"); - b2.ToTable(""Order""); + b2.ToTable("Order"); b2.WithOwner() - .HasForeignKey(""OrderDetailsOrderId""); + .HasForeignKey("OrderDetailsOrderId"); }); - b1.Navigation(""StreetAddress""); + b1.Navigation("StreetAddress"); }); - b.OwnsOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails"", ""OrderShippingDetails"", b1 => + b.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderDetails", "OrderShippingDetails", b1 => { - b1.Property(""OrderId"") - .HasColumnType(""int""); + b1.Property("OrderId") + .HasColumnType("int"); - b1.HasKey(""OrderId""); + b1.HasKey("OrderId"); - b1.ToTable(""Order""); + b1.ToTable("Order"); b1.WithOwner() - .HasForeignKey(""OrderId""); + .HasForeignKey("OrderId"); - b1.OwnsOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+StreetAddress"", ""StreetAddress"", b2 => + b1.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+StreetAddress", "StreetAddress", b2 => { - b2.Property(""OrderDetailsOrderId"") - .HasColumnType(""int""); + b2.Property("OrderDetailsOrderId") + .HasColumnType("int"); - b2.Property(""City"") - .HasColumnType(""nvarchar(max)""); + b2.Property("City") + .HasColumnType("nvarchar(max)"); - b2.HasKey(""OrderDetailsOrderId""); + b2.HasKey("OrderDetailsOrderId"); - b2.ToTable(""Order""); + b2.ToTable("Order"); b2.WithOwner() - .HasForeignKey(""OrderDetailsOrderId""); + .HasForeignKey("OrderDetailsOrderId"); }); - b1.Navigation(""StreetAddress""); + b1.Navigation("StreetAddress"); }); - b.OwnsOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderInfo"", ""OrderInfo"", b1 => + b.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+OrderInfo", "OrderInfo", b1 => { - b1.Property(""OrderId"") - .HasColumnType(""int""); + b1.Property("OrderId") + .HasColumnType("int"); - b1.HasKey(""OrderId""); + b1.HasKey("OrderId"); - b1.ToTable(""Order""); + b1.ToTable("Order"); b1.WithOwner() - .HasForeignKey(""OrderId""); + .HasForeignKey("OrderId"); - b1.OwnsOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+StreetAddress"", ""StreetAddress"", b2 => + b1.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+StreetAddress", "StreetAddress", b2 => { - b2.Property(""OrderInfoOrderId"") - .HasColumnType(""int""); + b2.Property("OrderInfoOrderId") + .HasColumnType("int"); - b2.Property(""City"") - .HasColumnType(""nvarchar(max)""); + b2.Property("City") + .HasColumnType("nvarchar(max)"); - b2.HasKey(""OrderInfoOrderId""); + b2.HasKey("OrderInfoOrderId"); - b2.ToTable(""Order""); + b2.ToTable("Order"); b2.WithOwner() - .HasForeignKey(""OrderInfoOrderId""); + .HasForeignKey("OrderInfoOrderId"); }); - b1.Navigation(""StreetAddress""); + b1.Navigation("StreetAddress"); }); - b.Navigation(""OrderBillingDetails""); + b.Navigation("OrderBillingDetails"); - b.Navigation(""OrderInfo""); + b.Navigation("OrderInfo"); - b.Navigation(""OrderShippingDetails""); - });"), + b.Navigation("OrderShippingDetails"); + }); +"""), o => { Assert.Equal(7, o.GetEntityTypes().Count()); @@ -3479,7 +3530,8 @@ public virtual void Owned_types_can_be_mapped_to_view() o => o.OwnedEntities, ownee => ownee.ToView("OwnedView")); }, - @"// +""" +// using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -3495,53 +3547,54 @@ partial class Snapshot : ModelSnapshot protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder.HasAnnotation(""Relational:MaxIdentifierLength"", 128); + modelBuilder.HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestOwner"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestOwner", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""TestOwner""); + b.ToTable("TestOwner"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestOwner"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestOwner", b => { - b.OwnsMany(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestOwnee"", ""OwnedEntities"", b1 => + b.OwnsMany("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestOwnee", "OwnedEntities", b1 => { - b1.Property(""TestOwnerId"") - .HasColumnType(""int""); + b1.Property("TestOwnerId") + .HasColumnType("int"); - b1.Property(""Id"") - .HasColumnType(""int""); + b1.Property("Id") + .HasColumnType("int"); - b1.Property(""TestEnum"") - .HasColumnType(""int""); + b1.Property("TestEnum") + .HasColumnType("int"); - b1.HasKey(""TestOwnerId"", ""Id""); + b1.HasKey("TestOwnerId", "Id"); b1.ToTable((string)null); - b1.ToView(""OwnedView"", (string)null); + b1.ToView("OwnedView", (string)null); b1.WithOwner() - .HasForeignKey(""TestOwnerId""); + .HasForeignKey("TestOwnerId"); }); - b.Navigation(""OwnedEntities""); + b.Navigation("OwnedEntities"); }); #pragma warning restore 612, 618 } } } -", + +""", model => { Assert.Equal(2, model.GetEntityTypes().Count()); @@ -3563,7 +3616,8 @@ public virtual void Snapshot_with_OwnedNavigationBuilder_HasCheckConstraint_comp ownee => ownee.ToTable( tb => tb.HasCheckConstraint("CK_TestOwnee_TestEnum_Enum_Constraint", "[TestEnum] IN (0, 1, 2)"))); }, - @"// +""" +// using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -3579,57 +3633,58 @@ partial class Snapshot : ModelSnapshot protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder.HasAnnotation(""Relational:MaxIdentifierLength"", 128); + modelBuilder.HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestOwner"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestOwner", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""TestOwner""); + b.ToTable("TestOwner"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestOwner"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestOwner", b => { - b.OwnsMany(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestOwnee"", ""OwnedEntities"", b1 => + b.OwnsMany("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+TestOwnee", "OwnedEntities", b1 => { - b1.Property(""TestOwnerId"") - .HasColumnType(""int""); + b1.Property("TestOwnerId") + .HasColumnType("int"); - b1.Property(""Id"") + b1.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b1.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b1.Property("Id")); - b1.Property(""TestEnum"") - .HasColumnType(""int""); + b1.Property("TestEnum") + .HasColumnType("int"); - b1.HasKey(""TestOwnerId"", ""Id""); + b1.HasKey("TestOwnerId", "Id"); - b1.ToTable(""TestOwnee"", t => + b1.ToTable("TestOwnee", t => { - t.HasCheckConstraint(""CK_TestOwnee_TestEnum_Enum_Constraint"", ""[TestEnum] IN (0, 1, 2)""); + t.HasCheckConstraint("CK_TestOwnee_TestEnum_Enum_Constraint", "[TestEnum] IN (0, 1, 2)"); }); b1.WithOwner() - .HasForeignKey(""TestOwnerId""); + .HasForeignKey("TestOwnerId"); }); - b.Navigation(""OwnedEntities""); + b.Navigation("OwnedEntities"); }); #pragma warning restore 612, 618 } } } -", + +""", model => { Assert.Equal(2, model.GetEntityTypes().Count()); @@ -3667,86 +3722,87 @@ public virtual void Owned_types_mapped_to_json_are_stored_in_snapshot() }); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id"") - .HasName(""PK_Custom""); + b.HasKey("Id") + .HasName("PK_Custom"); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.OwnsOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""EntityWithTwoProperties"", b1 => + b.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "EntityWithTwoProperties", b1 => { - b1.Property(""EntityWithOnePropertyId"") - .HasColumnType(""int""); + b1.Property("EntityWithOnePropertyId") + .HasColumnType("int"); - b1.Property(""AlternateId"") - .HasColumnType(""int"") - .HasAnnotation(""Relational:JsonPropertyName"", ""NotKey""); + b1.Property("AlternateId") + .HasColumnType("int") + .HasAnnotation("Relational:JsonPropertyName", "NotKey"); - b1.HasKey(""EntityWithOnePropertyId""); + b1.HasKey("EntityWithOnePropertyId"); - b1.ToTable(""EntityWithOneProperty""); + b1.ToTable("EntityWithOneProperty"); - b1.ToJson(""EntityWithTwoProperties""); + b1.ToJson("EntityWithTwoProperties"); - b1.WithOwner(""EntityWithOneProperty"") - .HasForeignKey(""EntityWithOnePropertyId""); + b1.WithOwner("EntityWithOneProperty") + .HasForeignKey("EntityWithOnePropertyId"); - b1.OwnsOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey"", ""EntityWithStringKey"", b2 => + b1.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey", "EntityWithStringKey", b2 => { - b2.Property(""EntityWithTwoPropertiesEntityWithOnePropertyId"") - .HasColumnType(""int""); + b2.Property("EntityWithTwoPropertiesEntityWithOnePropertyId") + .HasColumnType("int"); - b2.HasKey(""EntityWithTwoPropertiesEntityWithOnePropertyId""); + b2.HasKey("EntityWithTwoPropertiesEntityWithOnePropertyId"); - b2.ToTable(""EntityWithOneProperty""); + b2.ToTable("EntityWithOneProperty"); b2.WithOwner() - .HasForeignKey(""EntityWithTwoPropertiesEntityWithOnePropertyId""); + .HasForeignKey("EntityWithTwoPropertiesEntityWithOnePropertyId"); - b2.OwnsMany(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", ""Properties"", b3 => + b2.OwnsMany("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", "Properties", b3 => { - b3.Property(""EntityWithStringKeyEntityWithTwoPropertiesEntityWithOnePropertyId"") - .HasColumnType(""int""); + b3.Property("EntityWithStringKeyEntityWithTwoPropertiesEntityWithOnePropertyId") + .HasColumnType("int"); - b3.Property(""Id"") + b3.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - b3.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b3.Property("Name") + .HasColumnType("nvarchar(max)"); - b3.HasKey(""EntityWithStringKeyEntityWithTwoPropertiesEntityWithOnePropertyId"", ""Id""); + b3.HasKey("EntityWithStringKeyEntityWithTwoPropertiesEntityWithOnePropertyId", "Id"); - b3.ToTable(""EntityWithOneProperty""); + b3.ToTable("EntityWithOneProperty"); - b3.HasAnnotation(""Relational:JsonPropertyName"", ""JsonProps""); + b3.HasAnnotation("Relational:JsonPropertyName", "JsonProps"); b3.WithOwner() - .HasForeignKey(""EntityWithStringKeyEntityWithTwoPropertiesEntityWithOnePropertyId""); + .HasForeignKey("EntityWithStringKeyEntityWithTwoPropertiesEntityWithOnePropertyId"); }); - b2.Navigation(""Properties""); + b2.Navigation("Properties"); }); - b1.Navigation(""EntityWithOneProperty""); + b1.Navigation("EntityWithOneProperty"); - b1.Navigation(""EntityWithStringKey""); + b1.Navigation("EntityWithStringKey"); }); - b.Navigation(""EntityWithTwoProperties""); - });", usingSystem: false), + b.Navigation("EntityWithTwoProperties"); + }); +""", usingSystem: false), o => { var entityWithOneProperty = o.FindEntityType(typeof(EntityWithOneProperty)); @@ -3843,21 +3899,22 @@ public virtual void Property_annotations_are_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int"") - .HasAnnotation(""AnnotationName"", ""AnnotationValue""); + .HasColumnType("int") + .HasAnnotation("AnnotationName", "AnnotationValue"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); - });"), + b.ToTable("EntityWithOneProperty"); + }); +"""), o => Assert.Equal("AnnotationValue", o.GetEntityTypes().First().FindProperty("Id")["AnnotationName"]) ); @@ -3870,20 +3927,21 @@ public virtual void Custom_value_generator_is_ignored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); - });"), + b.ToTable("EntityWithOneProperty"); + }); +"""), o => Assert.Null(o.GetEntityTypes().First().FindProperty("Id")[CoreAnnotationNames.ValueGeneratorFactory]) ); @@ -3892,24 +3950,25 @@ public virtual void Property_isNullable_is_stored_in_snapshot() => Test( builder => builder.Entity().Property("Name").IsRequired(), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Name"") + b.Property("Name") .IsRequired() - .HasColumnType(""nvarchar(max)""); + .HasColumnType("nvarchar(max)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithStringProperty""); - });"), + b.ToTable("EntityWithStringProperty"); + }); +"""), o => Assert.False(o.GetEntityTypes().First().FindProperty("Name").IsNullable)); [ConditionalFact] @@ -3921,25 +3980,26 @@ public virtual void Property_ValueGenerated_value_is_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") + b.Property("AlternateId") .ValueGeneratedOnAdd() - .HasColumnType(""int"") + .HasColumnType("int") .HasDefaultValue(); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });", usingSystem: true), + b.ToTable("EntityWithTwoProperties"); + }); +""", usingSystem: true), o => Assert.Equal(ValueGenerated.OnAdd, o.GetEntityTypes().First().FindProperty("AlternateId").ValueGenerated)); [ConditionalFact] @@ -3953,24 +4013,25 @@ public virtual void Property_ValueGenerated_non_identity() .Metadata.SetValueGenerationStrategy(SqlServerValueGenerationStrategy.None); }), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithEnumType"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithEnumType", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int"") - .HasAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - b.Property(""Day"") + b.Property("Day") .ValueGeneratedOnAdd() - .HasColumnType(""bigint"") - .HasAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithEnumType""); - });"), + b.ToTable("EntityWithEnumType"); + }); +"""), model => { var id = model.GetEntityTypes().Single().GetProperty(nameof(EntityWithEnumType.Id)); @@ -3986,24 +4047,25 @@ public virtual void Property_maxLength_is_stored_in_snapshot() => Test( builder => builder.Entity().Property("Name").HasMaxLength(100), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Name"") + b.Property("Name") .HasMaxLength(100) - .HasColumnType(""nvarchar(100)""); + .HasColumnType("nvarchar(100)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithStringProperty""); - });"), + b.ToTable("EntityWithStringProperty"); + }); +"""), o => Assert.Equal(100, o.GetEntityTypes().First().FindProperty("Name").GetMaxLength())); [ConditionalFact] @@ -4011,24 +4073,25 @@ public virtual void Property_unicodeness_is_stored_in_snapshot() => Test( builder => builder.Entity().Property("Name").IsUnicode(false), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Name"") + b.Property("Name") .IsUnicode(false) - .HasColumnType(""varchar(max)""); + .HasColumnType("varchar(max)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithStringProperty""); - });"), + b.ToTable("EntityWithStringProperty"); + }); +"""), o => Assert.False(o.GetEntityTypes().First().FindProperty("Name").IsUnicode())); [ConditionalFact] @@ -4036,25 +4099,26 @@ public virtual void Property_fixedlengthness_is_stored_in_snapshot() => Test( builder => builder.Entity().Property("Name").IsFixedLength().HasMaxLength(100), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Name"") + b.Property("Name") .HasMaxLength(100) - .HasColumnType(""nchar(100)"") + .HasColumnType("nchar(100)") .IsFixedLength(); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithStringProperty""); - });"), + b.ToTable("EntityWithStringProperty"); + }); +"""), o => Assert.True(o.GetEntityTypes().First().FindProperty("Name").IsFixedLength())); [ConditionalFact] @@ -4065,24 +4129,25 @@ public virtual void Property_precision_is_stored_in_snapshot() .Property(nameof(EntityWithDecimalProperty.Price)) .HasPrecision(7), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithDecimalProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithDecimalProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Price"") + b.Property("Price") .HasPrecision(7) - .HasColumnType(""decimal(7,2)""); + .HasColumnType("decimal(7,2)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithDecimalProperty""); - });"), + b.ToTable("EntityWithDecimalProperty"); + }); +"""), o => { var property = o.GetEntityTypes().First().FindProperty(nameof(EntityWithDecimalProperty.Price)); @@ -4098,24 +4163,25 @@ public virtual void Property_precision_and_scale_is_stored_in_snapshot() .Property(nameof(EntityWithDecimalProperty.Price)) .HasPrecision(7, 3), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithDecimalProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithDecimalProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Price"") + b.Property("Price") .HasPrecision(7, 3) - .HasColumnType(""decimal(7,3)""); + .HasColumnType("decimal(7,3)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithDecimalProperty""); - });"), + b.ToTable("EntityWithDecimalProperty"); + }); +"""), o => { var property = o.GetEntityTypes().First().FindProperty(nameof(EntityWithDecimalProperty.Price)); @@ -4135,26 +4201,27 @@ public virtual void Many_facets_chained_in_snapshot() .HasAnnotation("AnnotationName", "AnnotationValue"); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Name"") + b.Property("Name") .HasMaxLength(100) .IsUnicode(false) - .HasColumnType(""varchar(100)"") - .HasAnnotation(""AnnotationName"", ""AnnotationValue""); + .HasColumnType("varchar(100)") + .HasAnnotation("AnnotationName", "AnnotationValue"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithStringProperty""); - });"), + b.ToTable("EntityWithStringProperty"); + }); +"""), o => { var property = o.GetEntityTypes().First().FindProperty("Name"); @@ -4172,24 +4239,25 @@ public virtual void Property_concurrencyToken_is_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") + b.Property("AlternateId") .IsConcurrencyToken() - .HasColumnType(""int""); + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.True(o.GetEntityTypes().First().FindProperty("AlternateId").IsConcurrencyToken)); [ConditionalFact] @@ -4201,24 +4269,25 @@ public virtual void Property_column_name_annotation_is_stored_in_snapshot_as_flu builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int"") - .HasColumnName(""CName""); + b.Property("AlternateId") + .HasColumnType("int") + .HasColumnName("CName"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal("CName", o.GetEntityTypes().First().FindProperty("AlternateId")["Relational:ColumnName"])); [ConditionalFact] @@ -4230,55 +4299,56 @@ public virtual void Property_column_name_on_specific_table_is_stored_in_snapshot builder.Entity().HasBaseType(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Discriminator"") + b.Property("Discriminator") .IsRequired() .HasMaxLength(34) - .HasColumnType(""nvarchar(34)""); + .HasColumnType("nvarchar(34)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""BaseEntity""); + b.ToTable("BaseEntity"); - b.HasDiscriminator(""Discriminator"").HasValue(""BaseEntity""); + b.HasDiscriminator("Discriminator").HasValue("BaseEntity"); b.UseTphMappingStrategy(); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedEntity", b => { - b.HasBaseType(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity""); + b.HasBaseType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"); - b.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b.Property("Name") + .HasColumnType("nvarchar(max)"); - b.HasDiscriminator().HasValue(""DerivedEntity""); + b.HasDiscriminator().HasValue("DerivedEntity"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DuplicateDerivedEntity"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DuplicateDerivedEntity", b => { - b.HasBaseType(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity""); + b.HasBaseType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseEntity"); - b.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b.Property("Name") + .HasColumnType("nvarchar(max)"); - b.ToTable(""BaseEntity"", t => + b.ToTable("BaseEntity", t => { - t.Property(""Name"") - .HasColumnName(""DuplicateDerivedEntity_Name""); + t.Property("Name") + .HasColumnName("DuplicateDerivedEntity_Name"); }); - b.HasDiscriminator().HasValue(""DuplicateDerivedEntity""); - });"), + b.HasDiscriminator().HasValue("DuplicateDerivedEntity"); + }); +"""), o => { Assert.Equal(3, o.GetEntityTypes().Count()); @@ -4307,23 +4377,24 @@ public virtual void Property_column_type_annotation_is_stored_in_snapshot_as_flu builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""CType""); + b.Property("AlternateId") + .HasColumnType("CType"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal("CType", o.GetEntityTypes().First().FindProperty("AlternateId")["Relational:ColumnType"])); [ConditionalFact] @@ -4335,25 +4406,26 @@ public virtual void Property_default_value_annotation_is_stored_in_snapshot_as_f builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") + b.Property("AlternateId") .ValueGeneratedOnAdd() - .HasColumnType(""int"") + .HasColumnType("int") .HasDefaultValue(1); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal(1, o.GetEntityTypes().First().FindProperty("AlternateId")["Relational:DefaultValue"])); [ConditionalFact] @@ -4365,25 +4437,26 @@ public virtual void Property_default_value_annotation_is_stored_in_snapshot_as_f builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") + b.Property("AlternateId") .ValueGeneratedOnAdd() - .HasColumnType(""int"") + .HasColumnType("int") .HasDefaultValue(); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });", + b.ToTable("EntityWithTwoProperties"); + }); +""", usingSystem: true), o => Assert.Equal(DBNull.Value, o.GetEntityTypes().First().FindProperty("AlternateId")["Relational:DefaultValue"])); @@ -4396,25 +4469,26 @@ public virtual void Property_default_value_sql_annotation_is_stored_in_snapshot_ builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") + b.Property("AlternateId") .ValueGeneratedOnAdd() - .HasColumnType(""int"") + .HasColumnType("int") .HasDefaultValueSql(); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal(string.Empty, o.GetEntityTypes().First().FindProperty("AlternateId")["Relational:DefaultValueSql"])); [ConditionalFact] @@ -4426,25 +4500,26 @@ public virtual void Property_default_value_sql_annotation_is_stored_in_snapshot_ builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") + b.Property("AlternateId") .ValueGeneratedOnAdd() - .HasColumnType(""int"") - .HasDefaultValueSql(""SQL""); + .HasColumnType("int") + .HasDefaultValueSql("SQL"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal("SQL", o.GetEntityTypes().First().FindProperty("AlternateId")["Relational:DefaultValueSql"])); [ConditionalFact] @@ -4456,25 +4531,26 @@ public virtual void Property_computed_column_sql_annotation_is_stored_in_snapsho builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") + b.Property("AlternateId") .ValueGeneratedOnAddOrUpdate() - .HasColumnType(""int"") - .HasComputedColumnSql(""SQL""); + .HasColumnType("int") + .HasComputedColumnSql("SQL"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal("SQL", o.GetEntityTypes().First().FindProperty("AlternateId")["Relational:ComputedColumnSql"])); [ConditionalFact] @@ -4486,25 +4562,26 @@ public virtual void Property_computed_column_sql_stored_annotation_is_stored_in_ builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") + b.Property("AlternateId") .ValueGeneratedOnAddOrUpdate() - .HasColumnType(""int"") - .HasComputedColumnSql(""SQL"", true); + .HasColumnType("int") + .HasComputedColumnSql("SQL", true); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => { Assert.Equal("SQL", o.GetEntityTypes().First().FindProperty("AlternateId")["Relational:ComputedColumnSql"]); @@ -4520,25 +4597,26 @@ public virtual void Property_computed_column_sql_annotation_is_stored_in_snapsho builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") + b.Property("AlternateId") .ValueGeneratedOnAddOrUpdate() - .HasColumnType(""int"") + .HasColumnType("int") .HasComputedColumnSql(); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal(string.Empty, o.GetEntityTypes().First().FindProperty("AlternateId")["Relational:ComputedColumnSql"])); [ConditionalFact] @@ -4546,25 +4624,26 @@ public virtual void Property_default_value_of_enum_type_is_stored_in_snapshot_wi => Test( builder => builder.Entity().Property(e => e.Day).HasDefaultValue(Days.Wed), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithEnumType"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithEnumType", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Day"") + b.Property("Day") .ValueGeneratedOnAdd() - .HasColumnType(""bigint"") + .HasColumnType("bigint") .HasDefaultValue(3L); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithEnumType""); - });"), + b.ToTable("EntityWithEnumType"); + }); +"""), o => Assert.Equal(3L, o.GetEntityTypes().First().FindProperty("Day")["Relational:DefaultValue"])); [ConditionalFact] @@ -4579,33 +4658,34 @@ public virtual void Property_enum_type_is_stored_in_snapshot_with_custom_convers new { Id = 1, Day = Days.Fri }); }), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithEnumType"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithEnumType", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Day"") + b.Property("Day") .IsRequired() .ValueGeneratedOnAdd() - .HasColumnType(""nvarchar(max)"") - .HasDefaultValue(""Wed""); + .HasColumnType("nvarchar(max)") + .HasDefaultValue("Wed"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithEnumType""); + b.ToTable("EntityWithEnumType"); b.HasData( new { Id = 1, - Day = ""Fri"" + Day = "Fri" }); - });"), + }); +"""), o => { var property = o.GetEntityTypes().First().FindProperty("Day"); @@ -4619,23 +4699,24 @@ public virtual void Property_of_nullable_enum() => Test( builder => builder.Entity().Property(e => e.Day), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithNullableEnumType"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithNullableEnumType", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Day"") - .HasColumnType(""bigint""); + b.Property("Day") + .HasColumnType("bigint"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithNullableEnumType""); - });"), + b.ToTable("EntityWithNullableEnumType"); + }); +"""), o => Assert.True(o.GetEntityTypes().First().FindProperty("Day").IsNullable)); [ConditionalFact] @@ -4644,23 +4725,24 @@ public virtual void Property_of_enum_to_nullable() builder => builder.Entity().Property(e => e.Day) .HasConversion(m => (long?)m, p => p.HasValue ? (Days)p.Value : default), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithEnumType"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithEnumType", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Day"") - .HasColumnType(""bigint""); + b.Property("Day") + .HasColumnType("bigint"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithEnumType""); - });", usingSystem: true), + b.ToTable("EntityWithEnumType"); + }); +""", usingSystem: true), o => Assert.False(o.GetEntityTypes().First().FindProperty("Day").IsNullable)); [ConditionalFact] @@ -4668,23 +4750,24 @@ public virtual void Property_of_nullable_enum_to_string() => Test( builder => builder.Entity().Property(e => e.Day).HasConversion(), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithNullableEnumType"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithNullableEnumType", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Day"") - .HasColumnType(""nvarchar(max)""); + b.Property("Day") + .HasColumnType("nvarchar(max)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithNullableEnumType""); - });"), + b.ToTable("EntityWithNullableEnumType"); + }); +"""), o => Assert.True(o.GetEntityTypes().First().FindProperty("Day").IsNullable)); [ConditionalFact] @@ -4697,25 +4780,26 @@ public virtual void Property_multiple_annotations_are_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int"") - .HasColumnName(""CName"") - .HasAnnotation(""AnnotationName"", ""AnnotationValue""); + b.Property("AlternateId") + .HasColumnType("int") + .HasColumnName("CName") + .HasAnnotation("AnnotationName", "AnnotationValue"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => { var property = o.GetEntityTypes().First().FindProperty("AlternateId"); @@ -4747,20 +4831,21 @@ public virtual void Property_without_column_type() }); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Building"", b => + GetHeading() + +""" + modelBuilder.Entity("Building", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""Buildings"", (string)null); - });"), + b.ToTable("Buildings", (string)null); + }); +"""), o => { var property = o.FindEntityType("Building").FindProperty("Id"); @@ -4783,20 +4868,21 @@ public virtual void Property_with_identity_column() }); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Building"", b => + GetHeading() + +""" + modelBuilder.Entity("Building", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""Buildings"", (string)null); - });"), + b.ToTable("Buildings", (string)null); + }); +"""), o => { var property = o.FindEntityType("Building").FindProperty("Id"); @@ -4821,20 +4907,21 @@ public virtual void Property_with_identity_column_custom_seed() }); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Building"", b => + GetHeading() + +""" + modelBuilder.Entity("Building", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id""), 5L); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 5L); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""Buildings"", (string)null); - });"), + b.ToTable("Buildings", (string)null); + }); +"""), o => { var property = o.FindEntityType("Building").FindProperty("Id"); @@ -4859,20 +4946,21 @@ public virtual void Property_with_identity_column_custom_increment() }); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Building"", b => + GetHeading() + +""" + modelBuilder.Entity("Building", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id""), 1L, 5); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 5); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""Buildings"", (string)null); - });"), + b.ToTable("Buildings", (string)null); + }); +"""), o => { var property = o.FindEntityType("Building").FindProperty("Id"); @@ -4897,20 +4985,21 @@ public virtual void Property_with_identity_column_custom_seed_increment() }); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Building"", b => + GetHeading() + +""" + modelBuilder.Entity("Building", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id""), 5L, 5); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 5L, 5); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""Buildings"", (string)null); - });"), + b.ToTable("Buildings", (string)null); + }); +"""), o => { var property = o.FindEntityType("Building").FindProperty("Id"); @@ -4928,24 +5017,25 @@ public virtual void Property_column_order_annotation_is_stored_in_snapshot_as_fl builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int"") + b.Property("AlternateId") + .HasColumnType("int") .HasColumnOrder(1); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal(1, o.GetEntityTypes().First().FindProperty("AlternateId").GetColumnOrder())); [ConditionalFact] @@ -4953,10 +5043,11 @@ public virtual void SQLServer_model_legacy_identity_seed_int_annotation() => Test( builder => builder.HasAnnotation(SqlServerAnnotationNames.IdentitySeed, 8), AddBoilerPlate( - @" - modelBuilder.HasAnnotation(""Relational:MaxIdentifierLength"", 128); +""" + modelBuilder.HasAnnotation("Relational:MaxIdentifierLength", 128); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 8L);"), + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 8L); +"""), o => Assert.Equal(8L, o.GetIdentitySeed())); [ConditionalFact] @@ -4969,23 +5060,24 @@ public virtual void SQLServer_property_legacy_identity_seed_int_annotation() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id""), 8L); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 8L); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal(8L, o.GetEntityTypes().First().FindProperty("Id").GetIdentitySeed())); #endregion @@ -5002,26 +5094,27 @@ public virtual void Key_annotations_are_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasAlternateKey(""AlternateId"") - .HasAnnotation(""AnnotationName"", ""AnnotationValue""); + b.HasAlternateKey("AlternateId") + .HasAnnotation("AnnotationName", "AnnotationValue"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal( "AnnotationValue", o.GetEntityTypes().First().GetKeys().Where(k => !k.IsPrimaryKey()).First()["AnnotationName"])); @@ -5034,22 +5127,23 @@ public virtual void Key_Fluent_APIs_are_properly_generated() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - SqlServerKeyBuilderExtensions.IsClustered(b.HasKey(""Id"")); + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("Id")); - b.ToTable(""EntityWithOneProperty""); - });"), + b.ToTable("EntityWithOneProperty"); + }); +"""), o => Assert.True(o.GetEntityTypes().First().GetKeys().Single(k => k.IsPrimaryKey()).IsClustered())); [ConditionalFact] @@ -5061,26 +5155,27 @@ public virtual void Key_name_annotation_is_stored_in_snapshot_as_fluent_api() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasAlternateKey(""AlternateId"") - .HasName(""KeyName""); + b.HasAlternateKey("AlternateId") + .HasName("KeyName"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal( "KeyName", o.GetEntityTypes().First().GetKeys().Where(k => !k.IsPrimaryKey()).First()["Relational:Name"])); @@ -5094,27 +5189,28 @@ public virtual void Key_multiple_annotations_are_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasAlternateKey(""AlternateId"") - .HasName(""IndexName"") - .HasAnnotation(""AnnotationName"", ""AnnotationValue""); + b.HasAlternateKey("AlternateId") + .HasName("IndexName") + .HasAnnotation("AnnotationName", "AnnotationValue"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => { var key = o.GetEntityTypes().First().GetKeys().Where(k => !k.IsPrimaryKey()).First(); @@ -5137,26 +5233,27 @@ public virtual void Index_annotations_are_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""AlternateId"") - .HasAnnotation(""AnnotationName"", ""AnnotationValue""); + b.HasIndex("AlternateId") + .HasAnnotation("AnnotationName", "AnnotationValue"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal("AnnotationValue", o.GetEntityTypes().First().GetIndexes().First()["AnnotationName"])); [ConditionalFact] @@ -5168,27 +5265,28 @@ public virtual void Index_Fluent_APIs_are_properly_generated() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""AlternateId""); + b.HasIndex("AlternateId"); - SqlServerIndexBuilderExtensions.IsClustered(b.HasIndex(""AlternateId"")); + SqlServerIndexBuilderExtensions.IsClustered(b.HasIndex("AlternateId")); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.True(o.GetEntityTypes().Single().GetIndexes().Single().IsClustered())); [ConditionalFact] @@ -5200,26 +5298,27 @@ public virtual void Index_IsUnique_is_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""AlternateId"") + b.HasIndex("AlternateId") .IsUnique(); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.True(o.GetEntityTypes().First().GetIndexes().First().IsUnique)); [ConditionalFact] @@ -5272,42 +5371,43 @@ public virtual void Index_IsDescending_is_stored_in_snapshot() }); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithThreeProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithThreeProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""X"") - .HasColumnType(""int""); + b.Property("X") + .HasColumnType("int"); - b.Property(""Y"") - .HasColumnType(""int""); + b.Property("Y") + .HasColumnType("int"); - b.Property(""Z"") - .HasColumnType(""int""); + b.Property("Z") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(new[] { ""X"", ""Y"", ""Z"" }, ""IX_all_ascending""); + b.HasIndex(new[] { "X", "Y", "Z" }, "IX_all_ascending"); - b.HasIndex(new[] { ""X"", ""Y"", ""Z"" }, ""IX_all_descending"") + b.HasIndex(new[] { "X", "Y", "Z" }, "IX_all_descending") .IsDescending(); - b.HasIndex(new[] { ""X"", ""Y"", ""Z"" }, ""IX_empty"") + b.HasIndex(new[] { "X", "Y", "Z" }, "IX_empty") .IsDescending(); - b.HasIndex(new[] { ""X"", ""Y"", ""Z"" }, ""IX_mixed"") + b.HasIndex(new[] { "X", "Y", "Z" }, "IX_mixed") .IsDescending(false, true, false); - b.HasIndex(new[] { ""X"", ""Y"", ""Z"" }, ""IX_unspecified""); + b.HasIndex(new[] { "X", "Y", "Z" }, "IX_unspecified"); - b.ToTable(""EntityWithThreeProperties""); - });"), + b.ToTable("EntityWithThreeProperties"); + }); +"""), o => { var entityType = o.GetEntityTypes().Single(); @@ -5340,26 +5440,27 @@ public virtual void Index_database_name_annotation_is_stored_in_snapshot_as_flue builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""AlternateId"") - .HasDatabaseName(""IndexName""); + b.HasIndex("AlternateId") + .HasDatabaseName("IndexName"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => { var index = o.GetEntityTypes().First().GetIndexes().First(); @@ -5377,26 +5478,27 @@ public virtual void Index_filter_is_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""AlternateId"") - .HasFilter(""AlternateId <> 0""); + b.HasIndex("AlternateId") + .HasFilter("AlternateId <> 0"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal( "AlternateId <> 0", o.GetEntityTypes().First().GetIndexes().First().GetFilter())); @@ -5411,26 +5513,27 @@ public virtual void Index_multiple_annotations_are_stored_in_snapshot() builder.Ignore(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(new[] { ""AlternateId"" }, ""IndexName"") - .HasAnnotation(""AnnotationName"", ""AnnotationValue""); + b.HasIndex(new[] { "AlternateId" }, "IndexName") + .HasAnnotation("AnnotationName", "AnnotationValue"); - b.ToTable(""EntityWithTwoProperties""); - });"), + b.ToTable("EntityWithTwoProperties"); + }); +"""), o => { var index = o.GetEntityTypes().First().GetIndexes().First(); @@ -5452,28 +5555,29 @@ public virtual void Index_with_default_constraint_name_exceeding_max() x.HasIndex(propertyName); }), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b.Property("Name") + .HasColumnType("nvarchar(max)"); - b.Property(""SomePropertyWithAnExceedinglyLongIdentifierThatCausesTheDefaultIndexNameToExceedTheMaximumIdentifierLimit"") - .HasColumnType(""nvarchar(450)""); + b.Property("SomePropertyWithAnExceedinglyLongIdentifierThatCausesTheDefaultIndexNameToExceedTheMaximumIdentifierLimit") + .HasColumnType("nvarchar(450)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""SomePropertyWithAnExceedinglyLongIdentifierThatCausesTheDefaultIndexNameToExceedTheMaximumIdentifierLimit""); + b.HasIndex("SomePropertyWithAnExceedinglyLongIdentifierThatCausesTheDefaultIndexNameToExceedTheMaximumIdentifierLimit"); - b.ToTable(""EntityWithStringProperty""); - });"), + b.ToTable("EntityWithStringProperty"); + }); +"""), model => Assert.Equal(128, model.GetEntityTypes().First().GetIndexes().First().GetDatabaseName().Length)); [ConditionalFact] @@ -5481,28 +5585,29 @@ public virtual void IndexAttribute_causes_column_to_have_key_or_index_column_len => Test( builder => builder.Entity(), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithIndexAttribute"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithIndexAttribute", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""FirstName"") - .HasColumnType(""nvarchar(450)""); + b.Property("FirstName") + .HasColumnType("nvarchar(450)"); - b.Property(""LastName"") - .HasColumnType(""nvarchar(450)""); + b.Property("LastName") + .HasColumnType("nvarchar(450)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""FirstName"", ""LastName""); + b.HasIndex("FirstName", "LastName"); - b.ToTable(""EntityWithIndexAttribute""); - });"), + b.ToTable("EntityWithIndexAttribute"); + }); +"""), model => Assert.Collection( model.GetEntityTypes().First().GetIndexes().First().Properties, @@ -5523,28 +5628,29 @@ public virtual void IndexAttribute_name_is_stored_in_snapshot() => Test( builder => builder.Entity(), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithNamedIndexAttribute"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithNamedIndexAttribute", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""FirstName"") - .HasColumnType(""nvarchar(450)""); + b.Property("FirstName") + .HasColumnType("nvarchar(450)"); - b.Property(""LastName"") - .HasColumnType(""nvarchar(450)""); + b.Property("LastName") + .HasColumnType("nvarchar(450)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(new[] { ""FirstName"", ""LastName"" }, ""NamedIndex""); + b.HasIndex(new[] { "FirstName", "LastName" }, "NamedIndex"); - b.ToTable(""EntityWithNamedIndexAttribute""); - });"), + b.ToTable("EntityWithNamedIndexAttribute"); + }); +"""), model => { var index = model.GetEntityTypes().First().GetIndexes().First(); @@ -5569,30 +5675,31 @@ public virtual void IndexAttribute_IsUnique_is_stored_in_snapshot() => Test( builder => builder.Entity(), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithUniqueIndexAttribute"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithUniqueIndexAttribute", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""FirstName"") - .HasColumnType(""nvarchar(450)""); + b.Property("FirstName") + .HasColumnType("nvarchar(450)"); - b.Property(""LastName"") - .HasColumnType(""nvarchar(450)""); + b.Property("LastName") + .HasColumnType("nvarchar(450)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""FirstName"", ""LastName"") + b.HasIndex("FirstName", "LastName") .IsUnique() - .HasFilter(""[FirstName] IS NOT NULL AND [LastName] IS NOT NULL""); + .HasFilter("[FirstName] IS NOT NULL AND [LastName] IS NOT NULL"); - b.ToTable(""EntityWithUniqueIndexAttribute""); - });"), + b.ToTable("EntityWithUniqueIndexAttribute"); + }); +"""), model => { var index = model.GetEntityTypes().First().GetIndexes().First(); @@ -5621,27 +5728,28 @@ public virtual void IndexAttribute_IncludeProperties_generated_without_fluent_ap x.HasIndex(e => e.Id).IncludeProperties(e => e.Name); }), AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Name"") - .HasColumnType(""nvarchar(max)""); + b.Property("Name") + .HasColumnType("nvarchar(max)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""Id""); + b.HasIndex("Id"); - SqlServerIndexBuilderExtensions.IncludeProperties(b.HasIndex(""Id""), new[] { ""Name"" }); + SqlServerIndexBuilderExtensions.IncludeProperties(b.HasIndex("Id"), new[] { "Name" }); - b.ToTable(""EntityWithStringProperty""); - });"), + b.ToTable("EntityWithStringProperty"); + }); +"""), model => { var index = model.GetEntityTypes().First().GetIndexes().First(); @@ -5664,56 +5772,57 @@ public virtual void ForeignKey_annotations_are_stored_in_snapshot() .HasAnnotation("AnnotationName", "AnnotationValue"); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""AlternateId"") + b.HasIndex("AlternateId") .IsUnique(); - b.ToTable(""EntityWithTwoProperties""); + b.ToTable("EntityWithTwoProperties"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", ""EntityWithOneProperty"") - .WithOne(""EntityWithTwoProperties"") - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""AlternateId"") + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", "EntityWithOneProperty") + .WithOne("EntityWithTwoProperties") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "AlternateId") .OnDelete(DeleteBehavior.Cascade) .IsRequired() - .HasAnnotation(""AnnotationName"", ""AnnotationValue""); + .HasAnnotation("AnnotationName", "AnnotationValue"); - b.Navigation(""EntityWithOneProperty""); + b.Navigation("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Navigation(""EntityWithTwoProperties""); - });"), + b.Navigation("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal( "AnnotationValue", o.FindEntityType(typeof(EntityWithTwoProperties)).GetForeignKeys().First()["AnnotationName"])); @@ -5730,46 +5839,47 @@ public virtual void ForeignKey_isRequired_is_stored_in_snapshot() .IsRequired(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey", b => { - b.Property(""Id"") - .HasColumnType(""nvarchar(450)""); + b.Property("Id") + .HasColumnType("nvarchar(450)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithStringKey""); + b.ToTable("EntityWithStringKey"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Name"") + b.Property("Name") .IsRequired() - .HasColumnType(""nvarchar(450)""); + .HasColumnType("nvarchar(450)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""Name"") + b.HasIndex("Name") .IsUnique(); - b.ToTable(""EntityWithStringProperty""); + b.ToTable("EntityWithStringProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey"", null) + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey", null) .WithOne() - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", ""Name"") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", "Name") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - });"), + }); +"""), o => Assert.False(o.FindEntityType(typeof(EntityWithStringProperty)).FindProperty("Name").IsNullable)); [ConditionalFact] @@ -5783,47 +5893,48 @@ public virtual void ForeignKey_isUnique_is_stored_in_snapshot() .HasForeignKey(e => e.Name); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey", b => { - b.Property(""Id"") - .HasColumnType(""nvarchar(450)""); + b.Property("Id") + .HasColumnType("nvarchar(450)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithStringKey""); + b.ToTable("EntityWithStringKey"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Name"") - .HasColumnType(""nvarchar(450)""); + b.Property("Name") + .HasColumnType("nvarchar(450)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""Name""); + b.HasIndex("Name"); - b.ToTable(""EntityWithStringProperty""); + b.ToTable("EntityWithStringProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey"", null) - .WithMany(""Properties"") - .HasForeignKey(""Name""); + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey", null) + .WithMany("Properties") + .HasForeignKey("Name"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey", b => { - b.Navigation(""Properties""); - });"), + b.Navigation("Properties"); + }); +"""), o => Assert.False(o.FindEntityType(typeof(EntityWithStringProperty)).GetForeignKeys().First().IsUnique)); [ConditionalFact] @@ -5838,55 +5949,56 @@ public virtual void ForeignKey_with_non_primary_principal_is_stored_in_snapshot( .HasPrincipalKey(e => e.AlternateId); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringAlternateKey"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringAlternateKey", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") + b.Property("AlternateId") .IsRequired() - .HasColumnType(""nvarchar(450)""); + .HasColumnType("nvarchar(450)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithStringAlternateKey""); + b.ToTable("EntityWithStringAlternateKey"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Name"") - .HasColumnType(""nvarchar(450)""); + b.Property("Name") + .HasColumnType("nvarchar(450)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""Name""); + b.HasIndex("Name"); - b.ToTable(""EntityWithStringProperty""); + b.ToTable("EntityWithStringProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringProperty", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringAlternateKey"", null) - .WithMany(""Properties"") - .HasForeignKey(""Name"") - .HasPrincipalKey(""AlternateId""); + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringAlternateKey", null) + .WithMany("Properties") + .HasForeignKey("Name") + .HasPrincipalKey("AlternateId"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringAlternateKey"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringAlternateKey", b => { - b.Navigation(""Properties""); - });"), + b.Navigation("Properties"); + }); +"""), o => Assert.False(o.FindEntityType(typeof(EntityWithStringProperty)).GetForeignKeys().First().IsUnique)); [ConditionalFact] @@ -5901,44 +6013,45 @@ public virtual void ForeignKey_deleteBehavior_is_stored_in_snapshot() builder.Entity().Ignore(e => e.EntityWithOneProperty); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") - .HasColumnType(""int""); + b.Property("Id") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); + b.ToTable("EntityWithTwoProperties"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""EntityWithTwoProperties"") + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "EntityWithTwoProperties") .WithMany() - .HasForeignKey(""Id"") + .HasForeignKey("Id") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation(""EntityWithTwoProperties""); - });"), + b.Navigation("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal( DeleteBehavior.Cascade, o.FindEntityType(typeof(EntityWithOneProperty)).GetForeignKeys().First().DeleteBehavior)); @@ -5953,49 +6066,50 @@ public virtual void ForeignKey_deleteBehavior_is_stored_in_snapshot_for_one_to_o .HasForeignKey(e => e.Id); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") - .HasColumnType(""int""); + b.Property("Id") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); + b.ToTable("EntityWithTwoProperties"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""EntityWithTwoProperties"") - .WithOne(""EntityWithOneProperty"") - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", ""Id"") + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "EntityWithTwoProperties") + .WithOne("EntityWithOneProperty") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", "Id") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation(""EntityWithTwoProperties""); + b.Navigation("EntityWithTwoProperties"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Navigation(""EntityWithOneProperty""); - });"), + b.Navigation("EntityWithOneProperty"); + }); +"""), o => Assert.Equal( DeleteBehavior.Cascade, o.FindEntityType(typeof(EntityWithOneProperty)).GetForeignKeys().First().DeleteBehavior)); @@ -6013,45 +6127,46 @@ public virtual void ForeignKey_name_preserved_when_generic() originalModel = builder.Model; }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithGenericKey"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithGenericKey", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""uniqueidentifier""); + .HasColumnType("uniqueidentifier"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithGenericKey""); + b.ToTable("EntityWithGenericKey"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithGenericProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithGenericProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Property"") - .HasColumnType(""uniqueidentifier""); + b.Property("Property") + .HasColumnType("uniqueidentifier"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""Property""); + b.HasIndex("Property"); - b.ToTable(""EntityWithGenericProperty""); + b.ToTable("EntityWithGenericProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithGenericProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithGenericProperty", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithGenericKey"", null) + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithGenericKey", null) .WithMany() - .HasForeignKey(""Property"") + .HasForeignKey("Property") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - });", usingSystem: true), + }); +""", usingSystem: true), model => { var originalParent = originalModel.FindEntityType(typeof(EntityWithGenericKey)); @@ -6092,56 +6207,57 @@ public virtual void ForeignKey_constraint_name_is_stored_in_snapshot_as_fluent_a .HasConstraintName("Constraint"); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""AlternateId"") + b.HasIndex("AlternateId") .IsUnique(); - b.ToTable(""EntityWithTwoProperties""); + b.ToTable("EntityWithTwoProperties"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", ""EntityWithOneProperty"") - .WithOne(""EntityWithTwoProperties"") - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""AlternateId"") + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", "EntityWithOneProperty") + .WithOne("EntityWithTwoProperties") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "AlternateId") .OnDelete(DeleteBehavior.Cascade) .IsRequired() - .HasConstraintName(""Constraint""); + .HasConstraintName("Constraint"); - b.Navigation(""EntityWithOneProperty""); + b.Navigation("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Navigation(""EntityWithTwoProperties""); - });"), + b.Navigation("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal( "Constraint", o.FindEntityType(typeof(EntityWithTwoProperties)).GetForeignKeys().First()["Relational:Name"])); @@ -6158,57 +6274,58 @@ public virtual void ForeignKey_multiple_annotations_are_stored_in_snapshot() .HasConstraintName("Constraint"); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""AlternateId"") + b.HasIndex("AlternateId") .IsUnique(); - b.ToTable(""EntityWithTwoProperties""); + b.ToTable("EntityWithTwoProperties"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", ""EntityWithOneProperty"") - .WithOne(""EntityWithTwoProperties"") - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""AlternateId"") + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", "EntityWithOneProperty") + .WithOne("EntityWithTwoProperties") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "AlternateId") .OnDelete(DeleteBehavior.Cascade) .IsRequired() - .HasConstraintName(""Constraint"") - .HasAnnotation(""AnnotationName"", ""AnnotationValue""); + .HasConstraintName("Constraint") + .HasAnnotation("AnnotationName", "AnnotationValue"); - b.Navigation(""EntityWithOneProperty""); + b.Navigation("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Navigation(""EntityWithTwoProperties""); - });"), + b.Navigation("EntityWithTwoProperties"); + }); +"""), o => { var fk = o.FindEntityType(typeof(EntityWithTwoProperties)).GetForeignKeys().First(); @@ -6227,63 +6344,64 @@ public virtual void Do_not_generate_entity_type_builder_again_if_no_foreign_key_ builder.Entity(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseType"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseType", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Discriminator"") + b.Property("Discriminator") .IsRequired() .HasMaxLength(13) - .HasColumnType(""nvarchar(13)""); + .HasColumnType("nvarchar(13)"); - b.Property(""NavigationId"") - .HasColumnType(""int""); + b.Property("NavigationId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""NavigationId""); + b.HasIndex("NavigationId"); - b.ToTable(""BaseType""); + b.ToTable("BaseType"); - b.HasDiscriminator(""Discriminator"").HasValue(""BaseType""); + b.HasDiscriminator("Discriminator").HasValue("BaseType"); b.UseTphMappingStrategy(); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedType"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+DerivedType", b => { - b.HasBaseType(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseType""); + b.HasBaseType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseType"); - b.HasDiscriminator().HasValue(""DerivedType""); + b.HasDiscriminator().HasValue("DerivedType"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseType"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+BaseType", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", ""Navigation"") + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", "Navigation") .WithMany() - .HasForeignKey(""NavigationId""); + .HasForeignKey("NavigationId"); - b.Navigation(""Navigation""); - });", usingSystem: true), + b.Navigation("Navigation"); + }); +""", usingSystem: true), o => { }); [ConditionalFact] @@ -6298,50 +6416,51 @@ public virtual void ForeignKey_principal_key_is_stored_in_snapshot() .HasPrincipalKey(e => e.AlternateId); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") - .HasColumnType(""int""); + b.Property("Id") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithTwoProperties""); + b.ToTable("EntityWithTwoProperties"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""EntityWithTwoProperties"") - .WithOne(""EntityWithOneProperty"") - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", ""Id"") - .HasPrincipalKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""AlternateId"") + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "EntityWithTwoProperties") + .WithOne("EntityWithOneProperty") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", "Id") + .HasPrincipalKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "AlternateId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation(""EntityWithTwoProperties""); + b.Navigation("EntityWithTwoProperties"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Navigation(""EntityWithOneProperty""); - });"), + b.Navigation("EntityWithOneProperty"); + }); +"""), o => { Assert.Equal(2, o.FindEntityType(typeof(EntityWithTwoProperties)).GetKeys().Count()); @@ -6362,53 +6481,54 @@ public virtual void ForeignKey_principal_key_with_non_default_name_is_stored_in_ builder.Entity().HasAlternateKey(e => e.AlternateId).HasAnnotation("Name", "Value"); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") - .HasColumnType(""int""); + b.Property("Id") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasAlternateKey(""AlternateId"") - .HasAnnotation(""Name"", ""Value""); + b.HasAlternateKey("AlternateId") + .HasAnnotation("Name", "Value"); - b.ToTable(""EntityWithTwoProperties""); + b.ToTable("EntityWithTwoProperties"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""EntityWithTwoProperties"") - .WithOne(""EntityWithOneProperty"") - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", ""Id"") - .HasPrincipalKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""AlternateId"") + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "EntityWithTwoProperties") + .WithOne("EntityWithOneProperty") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", "Id") + .HasPrincipalKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "AlternateId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation(""EntityWithTwoProperties""); + b.Navigation("EntityWithTwoProperties"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Navigation(""EntityWithOneProperty""); - });"), + b.Navigation("EntityWithOneProperty"); + }); +"""), o => { var entityType = o.FindEntityType(typeof(EntityWithTwoProperties)); @@ -6435,56 +6555,57 @@ public virtual void Navigation_annotations_are_stored_in_snapshot() .HasAnnotation("AnnotationName", "AnnotationValue"); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""AlternateId"") + b.HasIndex("AlternateId") .IsUnique(); - b.ToTable(""EntityWithTwoProperties""); + b.ToTable("EntityWithTwoProperties"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", ""EntityWithOneProperty"") - .WithOne(""EntityWithTwoProperties"") - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""AlternateId"") + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", "EntityWithOneProperty") + .WithOne("EntityWithTwoProperties") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "AlternateId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation(""EntityWithOneProperty"") - .HasAnnotation(""AnnotationName"", ""AnnotationValue""); + b.Navigation("EntityWithOneProperty") + .HasAnnotation("AnnotationName", "AnnotationValue"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Navigation(""EntityWithTwoProperties""); - });"), + b.Navigation("EntityWithTwoProperties"); + }); +"""), o => Assert.Equal( "AnnotationValue", o.FindEntityType(typeof(EntityWithTwoProperties)).GetNavigations().First()["AnnotationName"])); @@ -6502,56 +6623,57 @@ public virtual void Navigation_isRequired_is_stored_in_snapshot() .IsRequired(); }, AddBoilerPlate( - GetHeading() - + @" - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + GetHeading() + +""" + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithOneProperty""); + b.ToTable("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""AlternateId"") - .HasColumnType(""int""); + b.Property("AlternateId") + .HasColumnType("int"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.HasIndex(""AlternateId"") + b.HasIndex("AlternateId") .IsUnique(); - b.ToTable(""EntityWithTwoProperties""); + b.ToTable("EntityWithTwoProperties"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", b => { - b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", ""EntityWithOneProperty"") - .WithOne(""EntityWithTwoProperties"") - .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""AlternateId"") + b.HasOne("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", "EntityWithOneProperty") + .WithOne("EntityWithTwoProperties") + .HasForeignKey("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties", "AlternateId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation(""EntityWithOneProperty""); + b.Navigation("EntityWithOneProperty"); }); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithOneProperty", b => { - b.Navigation(""EntityWithTwoProperties"") + b.Navigation("EntityWithTwoProperties") .IsRequired(); - });"), + }); +"""), o => Assert.True(o.FindEntityType(typeof(EntityWithOneProperty)).GetNavigations().First().ForeignKey.IsRequiredDependent)); #endregion @@ -6698,7 +6820,8 @@ static List getAllProperties(IModel model) }); builder.Ignore(); }, - @"// +""" +// using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -6716,145 +6839,145 @@ partial class Snapshot : ModelSnapshot protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder.HasAnnotation(""Relational:MaxIdentifierLength"", 128); + modelBuilder.HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithManyProperties"", b => + modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithManyProperties", b => { - b.Property(""Id"") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType(""int""); + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(""Id"")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property(""Boolean"") - .HasColumnType(""bit""); + b.Property("Boolean") + .HasColumnType("bit"); - b.Property(""Byte"") - .HasColumnType(""tinyint""); + b.Property("Byte") + .HasColumnType("tinyint"); - b.Property(""Bytes"") - .HasColumnType(""varbinary(max)""); + b.Property("Bytes") + .HasColumnType("varbinary(max)"); - b.Property(""Character"") + b.Property("Character") .IsRequired() - .HasColumnType(""nvarchar(1)""); + .HasColumnType("nvarchar(1)"); - b.Property(""DateTime"") - .HasColumnType(""datetime2""); + b.Property("DateTime") + .HasColumnType("datetime2"); - b.Property(""DateTimeOffset"") - .HasColumnType(""datetimeoffset""); + b.Property("DateTimeOffset") + .HasColumnType("datetimeoffset"); - b.Property(""Decimal"") - .HasColumnType(""decimal(18,2)""); + b.Property("Decimal") + .HasColumnType("decimal(18,2)"); - b.Property(""Double"") - .HasColumnType(""float""); + b.Property("Double") + .HasColumnType("float"); - b.Property(""Enum16"") - .HasColumnType(""smallint""); + b.Property("Enum16") + .HasColumnType("smallint"); - b.Property(""Enum32"") - .HasColumnType(""int""); + b.Property("Enum32") + .HasColumnType("int"); - b.Property(""Enum64"") - .HasColumnType(""bigint""); + b.Property("Enum64") + .HasColumnType("bigint"); - b.Property(""Enum8"") - .HasColumnType(""tinyint""); + b.Property("Enum8") + .HasColumnType("tinyint"); - b.Property(""EnumS8"") - .HasColumnType(""smallint""); + b.Property("EnumS8") + .HasColumnType("smallint"); - b.Property(""EnumU16"") - .HasColumnType(""int""); + b.Property("EnumU16") + .HasColumnType("int"); - b.Property(""EnumU32"") - .HasColumnType(""bigint""); + b.Property("EnumU32") + .HasColumnType("bigint"); - b.Property(""EnumU64"") - .HasColumnType(""decimal(20,0)""); + b.Property("EnumU64") + .HasColumnType("decimal(20,0)"); - b.Property(""Int16"") - .HasColumnType(""smallint""); + b.Property("Int16") + .HasColumnType("smallint"); - b.Property(""Int32"") - .HasColumnType(""int""); + b.Property("Int32") + .HasColumnType("int"); - b.Property(""Int64"") - .HasColumnType(""bigint""); + b.Property("Int64") + .HasColumnType("bigint"); - b.Property(""OptionalProperty"") - .HasColumnType(""decimal(18,2)""); + b.Property("OptionalProperty") + .HasColumnType("decimal(18,2)"); - b.Property(""SignedByte"") - .HasColumnType(""smallint""); + b.Property("SignedByte") + .HasColumnType("smallint"); - b.Property(""Single"") - .HasColumnType(""real""); + b.Property("Single") + .HasColumnType("real"); - b.Property(""SpatialBGeometryCollection"") - .HasColumnType(""geography""); + b.Property("SpatialBGeometryCollection") + .HasColumnType("geography"); - b.Property(""SpatialBLineString"") - .HasColumnType(""geography""); + b.Property("SpatialBLineString") + .HasColumnType("geography"); - b.Property(""SpatialBMultiLineString"") - .HasColumnType(""geography""); + b.Property("SpatialBMultiLineString") + .HasColumnType("geography"); - b.Property(""SpatialBMultiPoint"") - .HasColumnType(""geography""); + b.Property("SpatialBMultiPoint") + .HasColumnType("geography"); - b.Property(""SpatialBMultiPolygon"") - .HasColumnType(""geography""); + b.Property("SpatialBMultiPolygon") + .HasColumnType("geography"); - b.Property(""SpatialBPoint"") - .HasColumnType(""geography""); + b.Property("SpatialBPoint") + .HasColumnType("geography"); - b.Property(""SpatialBPolygon"") - .HasColumnType(""geography""); + b.Property("SpatialBPolygon") + .HasColumnType("geography"); - b.Property(""SpatialCGeometryCollection"") - .HasColumnType(""geography""); + b.Property("SpatialCGeometryCollection") + .HasColumnType("geography"); - b.Property(""SpatialCLineString"") - .HasColumnType(""geography""); + b.Property("SpatialCLineString") + .HasColumnType("geography"); - b.Property(""SpatialCMultiLineString"") - .HasColumnType(""geography""); + b.Property("SpatialCMultiLineString") + .HasColumnType("geography"); - b.Property(""SpatialCMultiPoint"") - .HasColumnType(""geography""); + b.Property("SpatialCMultiPoint") + .HasColumnType("geography"); - b.Property(""SpatialCMultiPolygon"") - .HasColumnType(""geography""); + b.Property("SpatialCMultiPolygon") + .HasColumnType("geography"); - b.Property(""SpatialCPoint"") - .HasColumnType(""geography""); + b.Property("SpatialCPoint") + .HasColumnType("geography"); - b.Property(""SpatialCPolygon"") - .HasColumnType(""geography""); + b.Property("SpatialCPolygon") + .HasColumnType("geography"); - b.Property(""String"") - .HasColumnType(""nvarchar(max)""); + b.Property("String") + .HasColumnType("nvarchar(max)"); - b.Property(""TimeSpan"") - .HasColumnType(""time""); + b.Property("TimeSpan") + .HasColumnType("time"); - b.Property(""UnsignedInt16"") - .HasColumnType(""int""); + b.Property("UnsignedInt16") + .HasColumnType("int"); - b.Property(""UnsignedInt32"") - .HasColumnType(""bigint""); + b.Property("UnsignedInt32") + .HasColumnType("bigint"); - b.Property(""UnsignedInt64"") - .HasColumnType(""decimal(20,0)""); + b.Property("UnsignedInt64") + .HasColumnType("decimal(20,0)"); - b.HasKey(""Id""); + b.HasKey("Id"); - b.ToTable(""EntityWithManyProperties""); + b.ToTable("EntityWithManyProperties"); b.HasData( new @@ -6863,7 +6986,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) Boolean = true, Byte = (byte)55, Bytes = new byte[] { 44, 45 }, - Character = ""9"", + Character = "9", DateTime = new DateTime(1973, 9, 3, 12, 10, 42, 344, DateTimeKind.Utc), DateTimeOffset = new DateTimeOffset(new DateTime(1973, 9, 3, 12, 10, 42, 344, DateTimeKind.Unspecified), new TimeSpan(0, 1, 0, 0, 0)), Decimal = 50.0m, @@ -6881,21 +7004,21 @@ protected override void BuildModel(ModelBuilder modelBuilder) Int64 = 48L, SignedByte = (short)60, Single = 54f, - SpatialBGeometryCollection = (NetTopologySuite.Geometries.GeometryCollection)new NetTopologySuite.IO.WKTReader().Read(""SRID=4326;GEOMETRYCOLLECTION Z(LINESTRING Z(1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), LINESTRING Z(7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN), MULTIPOINT Z((1.1 2.2 NaN), (2.2 2.2 NaN), (2.2 1.1 NaN)), POLYGON Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN)), POLYGON Z((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), POINT Z(1.1 2.2 3.3), MULTILINESTRING Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), (7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN)), MULTIPOLYGON Z(((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), ((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN))))""), - SpatialBLineString = (NetTopologySuite.Geometries.LineString)new NetTopologySuite.IO.WKTReader().Read(""SRID=4326;LINESTRING (1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2)""), - SpatialBMultiLineString = (NetTopologySuite.Geometries.MultiLineString)new NetTopologySuite.IO.WKTReader().Read(""SRID=4326;MULTILINESTRING ((1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2), (7.1 7.2, 20.2 20.2, 20.2 1.1, 70.1 70.2))""), - SpatialBMultiPoint = (NetTopologySuite.Geometries.MultiPoint)new NetTopologySuite.IO.WKTReader().Read(""SRID=4326;MULTIPOINT ((1.1 2.2), (2.2 2.2), (2.2 1.1))""), - SpatialBMultiPolygon = (NetTopologySuite.Geometries.MultiPolygon)new NetTopologySuite.IO.WKTReader().Read(""SRID=4326;MULTIPOLYGON (((10.1 20.2, 20.2 20.2, 20.2 10.1, 10.1 20.2)), ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2)))""), - SpatialBPoint = (NetTopologySuite.Geometries.Point)new NetTopologySuite.IO.WKTReader().Read(""SRID=4326;POINT Z(1.1 2.2 3.3)""), - SpatialBPolygon = (NetTopologySuite.Geometries.Polygon)new NetTopologySuite.IO.WKTReader().Read(""SRID=4326;POLYGON ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2))""), - SpatialCGeometryCollection = (NetTopologySuite.Geometries.GeometryCollection)new NetTopologySuite.IO.WKTReader().Read(""SRID=4326;GEOMETRYCOLLECTION Z(LINESTRING Z(1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), LINESTRING Z(7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN), MULTIPOINT Z((1.1 2.2 NaN), (2.2 2.2 NaN), (2.2 1.1 NaN)), POLYGON Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN)), POLYGON Z((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), POINT Z(1.1 2.2 3.3), MULTILINESTRING Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), (7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN)), MULTIPOLYGON Z(((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), ((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN))))""), - SpatialCLineString = (NetTopologySuite.Geometries.LineString)new NetTopologySuite.IO.WKTReader().Read(""SRID=4326;LINESTRING (1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2)""), - SpatialCMultiLineString = (NetTopologySuite.Geometries.MultiLineString)new NetTopologySuite.IO.WKTReader().Read(""SRID=4326;MULTILINESTRING ((1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2), (7.1 7.2, 20.2 20.2, 20.2 1.1, 70.1 70.2))""), - SpatialCMultiPoint = (NetTopologySuite.Geometries.MultiPoint)new NetTopologySuite.IO.WKTReader().Read(""SRID=4326;MULTIPOINT ((1.1 2.2), (2.2 2.2), (2.2 1.1))""), - SpatialCMultiPolygon = (NetTopologySuite.Geometries.MultiPolygon)new NetTopologySuite.IO.WKTReader().Read(""SRID=4326;MULTIPOLYGON (((10.1 20.2, 20.2 20.2, 20.2 10.1, 10.1 20.2)), ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2)))""), - SpatialCPoint = (NetTopologySuite.Geometries.Point)new NetTopologySuite.IO.WKTReader().Read(""SRID=4326;POINT Z(1.1 2.2 3.3)""), - SpatialCPolygon = (NetTopologySuite.Geometries.Polygon)new NetTopologySuite.IO.WKTReader().Read(""SRID=4326;POLYGON ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2))""), - String = ""FortyThree"", + SpatialBGeometryCollection = (NetTopologySuite.Geometries.GeometryCollection)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;GEOMETRYCOLLECTION Z(LINESTRING Z(1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), LINESTRING Z(7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN), MULTIPOINT Z((1.1 2.2 NaN), (2.2 2.2 NaN), (2.2 1.1 NaN)), POLYGON Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN)), POLYGON Z((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), POINT Z(1.1 2.2 3.3), MULTILINESTRING Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), (7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN)), MULTIPOLYGON Z(((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), ((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN))))"), + SpatialBLineString = (NetTopologySuite.Geometries.LineString)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;LINESTRING (1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2)"), + SpatialBMultiLineString = (NetTopologySuite.Geometries.MultiLineString)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTILINESTRING ((1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2), (7.1 7.2, 20.2 20.2, 20.2 1.1, 70.1 70.2))"), + SpatialBMultiPoint = (NetTopologySuite.Geometries.MultiPoint)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTIPOINT ((1.1 2.2), (2.2 2.2), (2.2 1.1))"), + SpatialBMultiPolygon = (NetTopologySuite.Geometries.MultiPolygon)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTIPOLYGON (((10.1 20.2, 20.2 20.2, 20.2 10.1, 10.1 20.2)), ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2)))"), + SpatialBPoint = (NetTopologySuite.Geometries.Point)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;POINT Z(1.1 2.2 3.3)"), + SpatialBPolygon = (NetTopologySuite.Geometries.Polygon)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;POLYGON ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2))"), + SpatialCGeometryCollection = (NetTopologySuite.Geometries.GeometryCollection)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;GEOMETRYCOLLECTION Z(LINESTRING Z(1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), LINESTRING Z(7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN), MULTIPOINT Z((1.1 2.2 NaN), (2.2 2.2 NaN), (2.2 1.1 NaN)), POLYGON Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN)), POLYGON Z((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), POINT Z(1.1 2.2 3.3), MULTILINESTRING Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), (7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN)), MULTIPOLYGON Z(((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), ((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN))))"), + SpatialCLineString = (NetTopologySuite.Geometries.LineString)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;LINESTRING (1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2)"), + SpatialCMultiLineString = (NetTopologySuite.Geometries.MultiLineString)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTILINESTRING ((1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2), (7.1 7.2, 20.2 20.2, 20.2 1.1, 70.1 70.2))"), + SpatialCMultiPoint = (NetTopologySuite.Geometries.MultiPoint)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTIPOINT ((1.1 2.2), (2.2 2.2), (2.2 1.1))"), + SpatialCMultiPolygon = (NetTopologySuite.Geometries.MultiPolygon)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTIPOLYGON (((10.1 20.2, 20.2 20.2, 20.2 10.1, 10.1 20.2)), ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2)))"), + SpatialCPoint = (NetTopologySuite.Geometries.Point)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;POINT Z(1.1 2.2 3.3)"), + SpatialCPolygon = (NetTopologySuite.Geometries.Polygon)new NetTopologySuite.IO.WKTReader().Read("SRID=4326;POLYGON ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2))"), + String = "FortyThree", TimeSpan = new TimeSpan(2, 3, 52, 53, 0), UnsignedInt16 = 56, UnsignedInt32 = 57L, @@ -6907,7 +7030,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) Boolean = true, Byte = (byte)55, Bytes = new byte[] { 44, 45 }, - Character = ""9"", + Character = "9", DateTime = new DateTime(1973, 9, 3, 12, 10, 42, 344, DateTimeKind.Utc), DateTimeOffset = new DateTimeOffset(new DateTime(1973, 9, 3, 12, 10, 42, 344, DateTimeKind.Unspecified), new TimeSpan(0, -1, 0, 0, 0)), Decimal = -50.0m, @@ -6925,7 +7048,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) Int64 = -48L, SignedByte = (short)-60, Single = -54f, - String = ""FortyThree"", + String = "FortyThree", TimeSpan = new TimeSpan(-2, -2, -7, -7, 0), UnsignedInt16 = 56, UnsignedInt32 = 57L, @@ -6936,7 +7059,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) } } } -", + +""", (snapshotModel, originalModel) => { var originalProperties = getAllProperties(originalModel); @@ -7062,14 +7186,12 @@ protected override void BuildModel(ModelBuilder modelBuilder) #endregion protected virtual string GetHeading(bool empty = false) - => @" - modelBuilder.HasAnnotation(""Relational:MaxIdentifierLength"", 128); + => """ + modelBuilder.HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);" - + (empty - ? null - : @" -"); +""" + (empty ? null : Environment.NewLine); protected virtual ICollection GetReferences() => new List @@ -7082,11 +7204,12 @@ protected virtual ICollection GetReferences() }; protected virtual string AddBoilerPlate(string code, bool usingSystem = false) - => $@"// -{(usingSystem + => $$""" +// +{{(usingSystem ? @"using System; " - : "")}using Microsoft.EntityFrameworkCore; + : "")}}using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; @@ -7094,18 +7217,20 @@ protected virtual string AddBoilerPlate(string code, bool usingSystem = false) #nullable disable namespace RootNamespace -{{ +{ [DbContext(typeof(DbContext))] partial class Snapshot : ModelSnapshot - {{ + { protected override void BuildModel(ModelBuilder modelBuilder) - {{ -#pragma warning disable 612, 618{code} + { +#pragma warning disable 612, 618 +{{code}} #pragma warning restore 612, 618 - }} - }} -}} -"; + } + } +} + +"""; protected void Test(Action buildModel, string expectedCode, Action assert) => Test(buildModel, expectedCode, (m, _) => assert(m)); diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs index 2162f5ac708..0c3d97ca0fa 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs @@ -13,8 +13,6 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal { public class CSharpDbContextGeneratorTest : ModelCodeGeneratorTestBase { - private static readonly string _nl = Environment.NewLine; - public CSharpDbContextGeneratorTest(ModelCodeGeneratorTestFixture fixture, ITestOutputHelper output) : base(fixture, output) { @@ -28,7 +26,8 @@ public Task Empty_model() code => { AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -46,10 +45,8 @@ public TestDbContext(DbContextOptions options) } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -58,7 +55,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); Assert.Empty(code.AdditionalFiles); @@ -73,7 +70,8 @@ public Task SuppressConnectionStringWarning_works() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -91,7 +89,7 @@ public TestDbContext(DbContextOptions options) } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -100,7 +98,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); Assert.Empty(code.AdditionalFiles); @@ -115,7 +113,8 @@ public Task SuppressOnConfiguring_works() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -135,7 +134,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); Assert.Empty(code.AdditionalFiles); @@ -222,12 +221,12 @@ public void Plugins_work() ConnectionString = "Initial Catalog=TestDatabase" }); - Assert.Contains( - @"optionsBuilder" - + _nl - + @" .UseSqlServer(""Initial Catalog=TestDatabase"", x => x.SetProviderOption())" - + _nl - + @" .SetContextOption();", + AssertContains( +""" +optionsBuilder + .UseSqlServer("Initial Catalog=TestDatabase", x => x.SetProviderOption()) + .SetContextOption(); +""", scaffoldedModel.ContextFile.Code); } @@ -395,8 +394,11 @@ public Task ValueGenerated_works() new ModelCodeGenerationOptions(), code => { - Assert.Contains( - @$"Property(e => e.ValueGeneratedOnAdd){_nl} .ValueGeneratedOnAdd()", + AssertContains( +""" +Property(e => e.ValueGeneratedOnAdd) + .ValueGeneratedOnAdd() +""", code.ContextFile.Code); Assert.Contains("Property(e => e.ValueGeneratedOnAddOrUpdate).ValueGeneratedOnAddOrUpdate()", code.ContextFile.Code); Assert.Contains("Property(e => e.ConcurrencyToken).IsConcurrencyToken()", code.ContextFile.Code); @@ -556,7 +558,8 @@ public Task Entity_with_indexes_and_use_data_annotations_false_always_generates_ code => { AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -576,22 +579,20 @@ public TestDbContext(DbContextOptions options) public virtual DbSet EntityWithIndexes { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { - entity.HasIndex(e => new { e.A, e.B }, ""IndexOnAAndB"") + entity.HasIndex(e => new { e.A, e.B }, "IndexOnAAndB") .IsUnique() .IsDescending(false, true); - entity.HasIndex(e => new { e.B, e.C }, ""IndexOnBAndC"") - .HasFilter(""Filter SQL"") - .HasAnnotation(""AnnotationName"", ""AnnotationValue""); + entity.HasIndex(e => new { e.B, e.C }, "IndexOnBAndC") + .HasFilter("Filter SQL") + .HasAnnotation("AnnotationName", "AnnotationValue"); entity.Property(e => e.Id).UseIdentityColumn(); }); @@ -601,7 +602,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, model => @@ -631,7 +632,8 @@ public Task Entity_with_indexes_and_use_data_annotations_true_generates_fluent_A code => { AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -651,18 +653,16 @@ public TestDbContext(DbContextOptions options) public virtual DbSet EntityWithIndexes { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { - entity.HasIndex(e => new { e.B, e.C }, ""IndexOnBAndC"") - .HasFilter(""Filter SQL"") - .HasAnnotation(""AnnotationName"", ""AnnotationValue""); + entity.HasIndex(e => new { e.B, e.C }, "IndexOnBAndC") + .HasFilter("Filter SQL") + .HasAnnotation("AnnotationName", "AnnotationValue"); entity.Property(e => e.Id).UseIdentityColumn(); }); @@ -672,7 +672,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, model => @@ -705,7 +705,8 @@ public Task Indexes_with_descending() code => { AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -725,24 +726,22 @@ public TestDbContext(DbContextOptions options) public virtual DbSet EntityWithIndexes { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { - entity.HasIndex(e => new { e.X, e.Y, e.Z }, ""IX_all_ascending""); + entity.HasIndex(e => new { e.X, e.Y, e.Z }, "IX_all_ascending"); - entity.HasIndex(e => new { e.X, e.Y, e.Z }, ""IX_all_descending"").IsDescending(); + entity.HasIndex(e => new { e.X, e.Y, e.Z }, "IX_all_descending").IsDescending(); - entity.HasIndex(e => new { e.X, e.Y, e.Z }, ""IX_empty"").IsDescending(); + entity.HasIndex(e => new { e.X, e.Y, e.Z }, "IX_empty").IsDescending(); - entity.HasIndex(e => new { e.X, e.Y, e.Z }, ""IX_mixed"").IsDescending(false, true, false); + entity.HasIndex(e => new { e.X, e.Y, e.Z }, "IX_mixed").IsDescending(false, true, false); - entity.HasIndex(e => new { e.X, e.Y, e.Z }, ""IX_unspecified""); + entity.HasIndex(e => new { e.X, e.Y, e.Z }, "IX_unspecified"); entity.Property(e => e.Id).UseIdentityColumn(); }); @@ -752,7 +751,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, model => @@ -804,7 +803,8 @@ public Task Entity_lambda_uses_correct_identifiers() code => { AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -826,16 +826,14 @@ public TestDbContext(DbContextOptions options) public virtual DbSet PrincipalEntity { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { - entity.HasIndex(e => e.DependentId, ""IX_DependentEntity_DependentId"").IsUnique(); + entity.HasIndex(e => e.DependentId, "IX_DependentEntity_DependentId").IsUnique(); entity.Property(e => e.Id).UseIdentityColumn(); @@ -856,7 +854,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, model => { }); @@ -876,7 +874,8 @@ public Task Column_type_is_not_scaffolded_as_annotation() code => { AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -896,10 +895,8 @@ public TestDbContext(DbContextOptions options) public virtual DbSet Employee { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -907,8 +904,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { entity.Property(e => e.Id).UseIdentityColumn(); entity.Property(e => e.HireDate) - .HasColumnType(""date"") - .HasColumnName(""hiring_date""); + .HasColumnType("date") + .HasColumnName("hiring_date"); }); OnModelCreatingPartial(modelBuilder); @@ -916,7 +913,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, model => @@ -946,7 +943,8 @@ public Task Global_namespace_works() code => { AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -964,10 +962,8 @@ public TestDbContext(DbContextOptions options) public virtual DbSet MyEntity { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -981,7 +977,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); Assert.DoesNotContain("namespace ", Assert.Single(code.AdditionalFiles).Code); @@ -1030,7 +1026,8 @@ public Task Fluent_calls_in_custom_namespaces_work() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using CustomTestNamespace; using Microsoft.EntityFrameworkCore; @@ -1053,7 +1050,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); Assert.Empty(code.AdditionalFiles); @@ -1081,7 +1078,8 @@ public async Task Temporal_table_works() code => { AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -1101,10 +1099,8 @@ public TestDbContext(DbContextOptions options) public virtual DbSet Customer { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -1112,13 +1108,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { entity.ToTable(tb => tb.IsTemporal(ttb => { - ttb.UseHistoryTable(""CustomerHistory""); + ttb.UseHistoryTable("CustomerHistory"); ttb - .HasPeriodStart(""PeriodStart"") - .HasColumnName(""PeriodStart""); + .HasPeriodStart("PeriodStart") + .HasColumnName("PeriodStart"); ttb - .HasPeriodEnd(""PeriodEnd"") - .HasColumnName(""PeriodEnd""); + .HasPeriodEnd("PeriodEnd") + .HasColumnName("PeriodEnd"); })); entity.Property(e => e.Id).UseIdentityColumn(); @@ -1129,7 +1125,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, model => @@ -1147,18 +1143,15 @@ public Task Sequences_work() .HasMax(100) .IsCyclic(), new ModelCodeGenerationOptions(), - code => Assert.Contains( - @".HasSequence(""EvenNumbers"", ""dbo"")" - + _nl - + " .StartsAt(2L)" - + _nl - + " .IncrementsBy(2)" - + _nl - + " .HasMin(2L)" - + _nl - + " .HasMax(100L)" - + _nl - + " .IsCyclic();", + code => AssertContains( +""" +.HasSequence("EvenNumbers", "dbo") + .StartsAt(2L) + .IncrementsBy(2) + .HasMin(2L) + .HasMax(100L) + .IsCyclic(); +""", code.ContextFile.Code), model => { @@ -1193,7 +1186,8 @@ public Task Trigger_works() code => { AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -1213,10 +1207,8 @@ public TestDbContext(DbContextOptions options) public virtual DbSet Employee { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -1224,8 +1216,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { entity.ToTable(tb => { - tb.HasTrigger(""Trigger1""); - tb.HasTrigger(""Trigger2""); + tb.HasTrigger("Trigger1"); + tb.HasTrigger("Trigger2"); }); entity.Property(e => e.Id).UseIdentityColumn(); @@ -1236,7 +1228,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, model => @@ -1264,7 +1256,8 @@ public Task ValueGenerationStrategy_works_when_none() code => { AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; @@ -1285,16 +1278,14 @@ public TestDbContext(DbContextOptions options) public virtual DbSet Channel { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { - entity.Property(e => e.Id).HasAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + entity.Property(e => e.Id).HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); }); OnModelCreatingPartial(modelBuilder); @@ -1302,7 +1293,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, model => diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs index e8be03c4d58..35e095cd656 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs @@ -23,7 +23,8 @@ public Task KeylessAttribute_is_generated_for_key_less_entity() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -35,11 +36,12 @@ namespace TestNamespace; public partial class Vista { } -", +""", code.AdditionalFiles.Single(f => f.Path == "Vista.cs")); AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -59,10 +61,8 @@ public TestDbContext(DbContextOptions options) public virtual DbSet Vista { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -71,7 +71,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, model => @@ -98,7 +98,8 @@ public Task TableAttribute_is_generated_for_custom_name() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -106,13 +107,13 @@ public Task TableAttribute_is_generated_for_custom_name() namespace TestNamespace; -[Table(""Vistas"")] +[Table("Vistas")] public partial class Vista { [Key] public int Id { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Vista.cs")); }, model => @@ -141,7 +142,8 @@ public Task TableAttribute_is_not_generated_for_default_schema() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -154,7 +156,7 @@ public partial class Vista [Key] public int Id { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Vista.cs")); }, model => @@ -183,7 +185,8 @@ public Task TableAttribute_is_generated_for_non_default_schema() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -191,13 +194,13 @@ public Task TableAttribute_is_generated_for_non_default_schema() namespace TestNamespace; -[Table(""Vista"", Schema = ""custom"")] +[Table("Vista", Schema = "custom")] public partial class Vista { [Key] public int Id { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Vista.cs")); }, model => @@ -215,7 +218,8 @@ public Task TableAttribute_is_not_generated_for_views() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -227,7 +231,7 @@ namespace TestNamespace; public partial class Vista { } -", +""", code.AdditionalFiles.Single(f => f.Path == "Vista.cs")); }, model => @@ -262,7 +266,8 @@ public Task IndexAttribute_is_generated_for_multiple_indexes_with_name_unique_de code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -270,9 +275,9 @@ public Task IndexAttribute_is_generated_for_multiple_indexes_with_name_unique_de namespace TestNamespace; -[Index(""C"")] -[Index(""A"", ""B"", Name = ""IndexOnAAndB"", IsUnique = true, IsDescending = new[] { true, false })] -[Index(""B"", ""C"", Name = ""IndexOnBAndC"")] +[Index("C")] +[Index("A", "B", Name = "IndexOnAAndB", IsUnique = true, IsDescending = new[] { true, false })] +[Index("B", "C", Name = "IndexOnBAndC")] public partial class EntityWithIndexes { [Key] @@ -284,7 +289,7 @@ public partial class EntityWithIndexes public int C { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "EntityWithIndexes.cs")); }, model => @@ -318,7 +323,8 @@ public Task IndexAttribute_is_generated_with_ascending_descending() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -326,9 +332,9 @@ public Task IndexAttribute_is_generated_with_ascending_descending() namespace TestNamespace; -[Index(""A"", ""B"", Name = ""AllAscending"")] -[Index(""A"", ""B"", Name = ""AllDescending"", AllDescending = true)] -[Index(""A"", ""B"", Name = ""PartiallyDescending"", IsDescending = new[] { true, false })] +[Index("A", "B", Name = "AllAscending")] +[Index("A", "B", Name = "AllDescending", AllDescending = true)] +[Index("A", "B", Name = "PartiallyDescending", IsDescending = new[] { true, false })] public partial class EntityWithAscendingDescendingIndexes { [Key] @@ -338,7 +344,7 @@ public partial class EntityWithAscendingDescendingIndexes public int B { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "EntityWithAscendingDescendingIndexes.cs")); }, model => @@ -386,7 +392,8 @@ public Task Entity_with_indexes_generates_IndexAttribute_only_for_indexes_withou code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -394,7 +401,7 @@ public Task Entity_with_indexes_generates_IndexAttribute_only_for_indexes_withou namespace TestNamespace; -[Index(""A"", ""B"", Name = ""IndexOnAAndB"", IsUnique = true)] +[Index("A", "B", Name = "IndexOnAAndB", IsUnique = true)] public partial class EntityWithIndexes { [Key] @@ -406,11 +413,12 @@ public partial class EntityWithIndexes public int C { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "EntityWithIndexes.cs")); AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -430,16 +438,14 @@ public TestDbContext(DbContextOptions options) public virtual DbSet EntityWithIndexes { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { - entity.HasIndex(e => new { e.B, e.C }, ""IndexOnBAndC"").HasFilter(""Filter SQL""); + entity.HasIndex(e => new { e.B, e.C }, "IndexOnBAndC").HasFilter("Filter SQL"); entity.Property(e => e.Id).UseIdentityColumn(); }); @@ -449,7 +455,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, model => @@ -470,7 +476,8 @@ public Task KeyAttribute_is_generated_for_single_property_and_no_fluent_api() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -483,11 +490,12 @@ public partial class Entity [Key] public int PrimaryKey { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Entity.cs")); AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -507,10 +515,8 @@ public TestDbContext(DbContextOptions options) public virtual DbSet Entity { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -524,7 +530,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, model => @@ -546,7 +552,8 @@ public Task KeyAttribute_is_generated_on_multiple_properties_but_and_uses_Primar code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -554,7 +561,7 @@ public Task KeyAttribute_is_generated_on_multiple_properties_but_and_uses_Primar namespace TestNamespace; -[PrimaryKey(""Key"", ""Serial"")] +[PrimaryKey("Key", "Serial")] public partial class Post { [Key] @@ -563,11 +570,12 @@ public partial class Post [Key] public int Serial { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Post.cs")); AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -587,10 +595,8 @@ public TestDbContext(DbContextOptions options) public virtual DbSet Post { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -599,7 +605,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, model => @@ -626,7 +632,8 @@ public Task Required_and_not_required_properties_without_nrt() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -648,7 +655,7 @@ public partial class Entity [Required] public string RequiredString { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Entity.cs")); }, model => @@ -678,7 +685,8 @@ public Task Required_and_not_required_properties_with_nrt() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -699,7 +707,7 @@ public partial class Entity public string RequiredString { get; set; } = null!; } -", +""", code.AdditionalFiles.Single(f => f.Path == "Entity.cs")); }, model => @@ -734,7 +742,8 @@ public Task Required_and_not_required_navigations_without_nrt() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -756,23 +765,23 @@ public partial class Entity public int RequiredValueNavigationId { get; set; } - [ForeignKey(""OptionalReferenceNavigationId"")] - [InverseProperty(""Entity"")] + [ForeignKey("OptionalReferenceNavigationId")] + [InverseProperty("Entity")] public virtual Dependent2 OptionalReferenceNavigation { get; set; } - [ForeignKey(""OptionalValueNavigationId"")] - [InverseProperty(""Entity"")] + [ForeignKey("OptionalValueNavigationId")] + [InverseProperty("Entity")] public virtual Dependent4 OptionalValueNavigation { get; set; } - [ForeignKey(""RequiredReferenceNavigationId"")] - [InverseProperty(""Entity"")] + [ForeignKey("RequiredReferenceNavigationId")] + [InverseProperty("Entity")] public virtual Dependent1 RequiredReferenceNavigation { get; set; } - [ForeignKey(""RequiredValueNavigationId"")] - [InverseProperty(""Entity"")] + [ForeignKey("RequiredValueNavigationId")] + [InverseProperty("Entity")] public virtual Dependent3 RequiredValueNavigation { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Entity.cs")); }, model => @@ -830,7 +839,8 @@ public Task Required_and_not_required_reference_navigations_with_nrt() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -843,19 +853,19 @@ public partial class Entity [Key] public int Id { get; set; } - [InverseProperty(""Entity"")] + [InverseProperty("Entity")] public virtual Dependent2? OptionalNavigationWithReferenceForeignKey { get; set; } - [InverseProperty(""Entity"")] + [InverseProperty("Entity")] public virtual Dependent4? OptionalNavigationWithValueForeignKey { get; set; } - [InverseProperty(""Entity"")] + [InverseProperty("Entity")] public virtual Dependent1? RequiredNavigationWithReferenceForeignKey { get; set; } - [InverseProperty(""Entity"")] + [InverseProperty("Entity")] public virtual Dependent3? RequiredNavigationWithValueForeignKey { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Entity.cs")); }, model => @@ -891,7 +901,8 @@ public Task Required_and_not_required_collection_navigations_with_nrt() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -912,23 +923,23 @@ public partial class Entity public int RequiredNavigationWithValueForeignKeyId { get; set; } - [ForeignKey(""OptionalNavigationWithReferenceForeignKeyId"")] - [InverseProperty(""Entity"")] + [ForeignKey("OptionalNavigationWithReferenceForeignKeyId")] + [InverseProperty("Entity")] public virtual Dependent2? OptionalNavigationWithReferenceForeignKey { get; set; } - [ForeignKey(""OptionalNavigationWithValueForeignKeyId"")] - [InverseProperty(""Entity"")] + [ForeignKey("OptionalNavigationWithValueForeignKeyId")] + [InverseProperty("Entity")] public virtual Dependent4? OptionalNavigationWithValueForeignKey { get; set; } - [ForeignKey(""RequiredNavigationWithReferenceForeignKeyId"")] - [InverseProperty(""Entity"")] + [ForeignKey("RequiredNavigationWithReferenceForeignKeyId")] + [InverseProperty("Entity")] public virtual Dependent1 RequiredNavigationWithReferenceForeignKey { get; set; } = null!; - [ForeignKey(""RequiredNavigationWithValueForeignKeyId"")] - [InverseProperty(""Entity"")] + [ForeignKey("RequiredNavigationWithValueForeignKeyId")] + [InverseProperty("Entity")] public virtual Dependent3 RequiredNavigationWithValueForeignKey { get; set; } = null!; } -", +""", code.AdditionalFiles.Single(f => f.Path == "Entity.cs")); for (var i = 1; i <= 4; i++) @@ -968,7 +979,8 @@ public Task RequiredAttribute_is_not_generated_for_key_property() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -981,7 +993,7 @@ public partial class Entity [Key] public string RequiredString { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Entity.cs")); }, model => @@ -1006,7 +1018,8 @@ public Task ColumnAttribute_is_generated_for_property() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1019,26 +1032,27 @@ public partial class Entity [Key] public int Id { get; set; } - [Column(""propertyA"")] + [Column("propertyA")] public string A { get; set; } - [Column(TypeName = ""nchar(10)"")] + [Column(TypeName = "nchar(10)")] public string B { get; set; } - [Column(""random"", TypeName = ""varchar(200)"")] + [Column("random", TypeName = "varchar(200)")] public string C { get; set; } - [Column(TypeName = ""numeric(18, 2)"")] + [Column(TypeName = "numeric(18, 2)")] public decimal D { get; set; } [StringLength(100)] public string E { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Entity.cs")); AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -1058,10 +1072,8 @@ public TestDbContext(DbContextOptions options) public virtual DbSet Entity { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -1075,7 +1087,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, model => @@ -1103,7 +1115,8 @@ public Task MaxLengthAttribute_is_generated_for_property() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1122,7 +1135,7 @@ public partial class Entity [MaxLength(10)] public byte[] B { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Entity.cs")); }, model => @@ -1149,7 +1162,8 @@ public Task UnicodeAttribute_is_generated_for_property() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1173,7 +1187,7 @@ public partial class Entity [StringLength(34)] public string C { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Entity.cs")); }, model => @@ -1202,7 +1216,8 @@ public Task PrecisionAttribute_is_generated_for_property() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1227,7 +1242,7 @@ public partial class Entity [Precision(3)] public DateTimeOffset D { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Entity.cs")); }, model => @@ -1256,7 +1271,8 @@ public Task Comments_are_generated() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1275,7 +1291,7 @@ public partial class Entity [Key] public int Id { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Entity.cs")); }, model => { }); @@ -1290,20 +1306,25 @@ public Task Comments_complex_are_generated() { x.ToTable( tb => tb.HasComment( - @"Entity Comment +""" +Entity Comment On multiple lines -With XML content
")); +With XML content
+""")); x.Property("Id").HasComment( - @"Property Comment +""" +Property Comment On multiple lines -With XML content
"); +With XML content
+"""); }) , new ModelCodeGenerationOptions { UseDataAnnotations = true }, code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1326,7 +1347,7 @@ public partial class Entity [Key] public int Id { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Entity.cs")); }, model => { }); @@ -1348,7 +1369,8 @@ public Task Properties_are_sorted_in_order_of_definition_in_table() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1365,7 +1387,7 @@ public partial class Entity public string LastProperty { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Entity.cs")); }, model => { }); @@ -1393,7 +1415,8 @@ public Task Navigation_properties_are_sorted_after_properties_and_collection_are code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1408,18 +1431,19 @@ public partial class Post public int? AuthorId { get; set; } - [ForeignKey(""AuthorId"")] - [InverseProperty(""Posts"")] + [ForeignKey("AuthorId")] + [InverseProperty("Posts")] public virtual Person Author { get; set; } - [InverseProperty(""Post"")] + [InverseProperty("Post")] public virtual ICollection Contributions { get; } = new List(); } -", +""", code.AdditionalFiles.Single(f => f.Path == "Post.cs")); AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1432,10 +1456,10 @@ public partial class Person [Key] public int Id { get; set; } - [InverseProperty(""Author"")] + [InverseProperty("Author")] public virtual ICollection Posts { get; } = new List(); } -", +""", code.AdditionalFiles.Single(f => f.Path == "Person.cs")); }, model => @@ -1474,7 +1498,8 @@ public Task ForeignKeyAttribute_is_generated_for_composite_fk() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1491,15 +1516,16 @@ public partial class Post public int? BlogId2 { get; set; } - [ForeignKey(""BlogId1, BlogId2"")] - [InverseProperty(""Posts"")] + [ForeignKey("BlogId1, BlogId2")] + [InverseProperty("Posts")] public virtual Blog BlogNavigation { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Post.cs")); AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -1521,10 +1547,8 @@ public TestDbContext(DbContextOptions options) public virtual DbSet Post { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -1538,7 +1562,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, model => @@ -1575,7 +1599,8 @@ public Task ForeignKeyAttribute_InversePropertyAttribute_is_not_generated_for_al code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1594,11 +1619,12 @@ public partial class Post public virtual Blog BlogNavigation { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Post.cs")); AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -1620,10 +1646,8 @@ public TestDbContext(DbContextOptions options) public virtual DbSet Post { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -1644,7 +1668,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, model => @@ -1674,7 +1698,8 @@ public Task InverseProperty_when_navigation_property_with_same_type_and_navigati code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1689,11 +1714,11 @@ public partial class Post public int? BlogId { get; set; } - [ForeignKey(""BlogId"")] - [InverseProperty(""Posts"")] + [ForeignKey("BlogId")] + [InverseProperty("Posts")] public virtual Blog Blog { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Post.cs")); }, model => @@ -1727,7 +1752,8 @@ public Task InverseProperty_when_navigation_property_with_same_type_and_property code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1742,11 +1768,11 @@ public partial class Post public int? Blog { get; set; } - [ForeignKey(""Blog"")] - [InverseProperty(""Posts"")] + [ForeignKey("Blog")] + [InverseProperty("Posts")] public virtual Blog BlogNavigation { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Post.cs")); }, model => @@ -1781,7 +1807,8 @@ public Task InverseProperty_when_navigation_property_with_same_type_and_other_na code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1798,15 +1825,15 @@ public partial class Post public int? OriginalBlogId { get; set; } - [ForeignKey(""BlogId"")] - [InverseProperty(""Posts"")] + [ForeignKey("BlogId")] + [InverseProperty("Posts")] public virtual Blog Blog { get; set; } - [ForeignKey(""OriginalBlogId"")] - [InverseProperty(""OriginalPosts"")] + [ForeignKey("OriginalBlogId")] + [InverseProperty("OriginalPosts")] public virtual Blog OriginalBlog { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "Post.cs")); }, model => @@ -1848,7 +1875,8 @@ public Task Entity_with_custom_annotation() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1856,17 +1884,18 @@ public Task Entity_with_custom_annotation() namespace TestNamespace; -[CustomEntityDataAnnotation(""first argument"")] +[CustomEntityDataAnnotation("first argument")] public partial class EntityWithAnnotation { [Key] public int Id { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "EntityWithAnnotation.cs")); AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -1886,10 +1915,8 @@ public TestDbContext(DbContextOptions options) public virtual DbSet EntityWithAnnotation { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -1903,7 +1930,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, assertModel: null, @@ -1925,7 +1952,8 @@ public Task Entity_property_with_custom_annotation() code => { AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -1936,14 +1964,15 @@ namespace TestNamespace; public partial class EntityWithPropertyAnnotation { [Key] - [CustomPropertyDataAnnotation(""first argument"")] + [CustomPropertyDataAnnotation("first argument")] public int Id { get; set; } } -", +""", code.AdditionalFiles.Single(f => f.Path == "EntityWithPropertyAnnotation.cs")); AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -1963,10 +1992,8 @@ public TestDbContext(DbContextOptions options) public virtual DbSet EntityWithPropertyAnnotation { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -1980,7 +2007,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); }, assertModel: null, @@ -2005,7 +2032,8 @@ public Task Scaffold_skip_navigations_default() code => { AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -2027,10 +2055,8 @@ public TestDbContext(DbContextOptions options) public virtual DbSet Post { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -2040,13 +2066,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.HasMany(d => d.Posts).WithMany(p => p.Blogs) .UsingEntity>( - ""BlogPost"", - r => r.HasOne().WithMany().HasForeignKey(""PostsId""), - l => l.HasOne().WithMany().HasForeignKey(""BlogsId""), + "BlogPost", + r => r.HasOne().WithMany().HasForeignKey("PostsId"), + l => l.HasOne().WithMany().HasForeignKey("BlogsId"), j => { - j.HasKey(""BlogsId"", ""PostsId""); - j.HasIndex(new[] { ""PostsId"" }, ""IX_BlogPost_PostsId""); + j.HasKey("BlogsId", "PostsId"); + j.HasIndex(new[] { "PostsId" }, "IX_BlogPost_PostsId"); }); }); @@ -2060,11 +2086,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; namespace TestNamespace; @@ -2075,11 +2102,12 @@ public partial class Blog public virtual ICollection Posts { get; } = new List(); } -", +""", code.AdditionalFiles.Single(e => e.Path == "Blog.cs")); AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; namespace TestNamespace; @@ -2090,7 +2118,7 @@ public partial class Post public virtual ICollection Blogs { get; } = new List(); } -", +""", code.AdditionalFiles.Single(e => e.Path == "Post.cs")); Assert.Equal(2, code.AdditionalFiles.Count); @@ -2136,7 +2164,8 @@ public Task Scaffold_skip_navigations_different_key_type() code => { AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -2158,10 +2187,8 @@ public TestDbContext(DbContextOptions options) public virtual DbSet Post { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -2171,13 +2198,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.HasMany(d => d.Posts).WithMany(p => p.Blogs) .UsingEntity>( - ""BlogPost"", - r => r.HasOne().WithMany().HasForeignKey(""PostsId""), - l => l.HasOne().WithMany().HasForeignKey(""BlogsId""), + "BlogPost", + r => r.HasOne().WithMany().HasForeignKey("PostsId"), + l => l.HasOne().WithMany().HasForeignKey("BlogsId"), j => { - j.HasKey(""BlogsId"", ""PostsId""); - j.HasIndex(new[] { ""PostsId"" }, ""IX_BlogPost_PostsId""); + j.HasKey("BlogsId", "PostsId"); + j.HasIndex(new[] { "PostsId" }, "IX_BlogPost_PostsId"); }); }); @@ -2186,11 +2213,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; namespace TestNamespace; @@ -2201,11 +2229,12 @@ public partial class Blog public virtual ICollection Posts { get; } = new List(); } -", +""", code.AdditionalFiles.Single(e => e.Path == "Blog.cs")); AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; namespace TestNamespace; @@ -2216,7 +2245,7 @@ public partial class Post public virtual ICollection Blogs { get; } = new List(); } -", +""", code.AdditionalFiles.Single(e => e.Path == "Post.cs")); Assert.Equal(2, code.AdditionalFiles.Count); @@ -2262,7 +2291,8 @@ public Task Scaffold_skip_navigations_default_data_annotations() code => { AssertFileContents( - @"using System; +$$""" +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -2284,10 +2314,8 @@ public TestDbContext(DbContextOptions options) public virtual DbSet Post { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning " - + DesignStrings.SensitiveInformationWarning - + @" - => optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); +#warning {{DesignStrings.SensitiveInformationWarning}} + => optionsBuilder.UseSqlServer("Initial Catalog=TestDatabase"); protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -2297,13 +2325,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.HasMany(d => d.Posts).WithMany(p => p.Blogs) .UsingEntity>( - ""BlogPost"", - r => r.HasOne().WithMany().HasForeignKey(""PostsId""), - l => l.HasOne().WithMany().HasForeignKey(""BlogsId""), + "BlogPost", + r => r.HasOne().WithMany().HasForeignKey("PostsId"), + l => l.HasOne().WithMany().HasForeignKey("BlogsId"), j => { - j.HasKey(""BlogsId"", ""PostsId""); - j.HasIndex(new[] { ""PostsId"" }, ""IX_BlogPost_PostsId""); + j.HasKey("BlogsId", "PostsId"); + j.HasIndex(new[] { "PostsId" }, "IX_BlogPost_PostsId"); }); }); @@ -2317,11 +2345,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } -", +""", code.ContextFile); AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -2334,15 +2363,16 @@ public partial class Blog [Key] public int Id { get; set; } - [ForeignKey(""BlogsId"")] - [InverseProperty(""Blogs"")] + [ForeignKey("BlogsId")] + [InverseProperty("Blogs")] public virtual ICollection Posts { get; } = new List(); } -", +""", code.AdditionalFiles.Single(e => e.Path == "Blog.cs")); AssertFileContents( - @"using System; +""" +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -2355,11 +2385,11 @@ public partial class Post [Key] public int Id { get; set; } - [ForeignKey(""PostsId"")] - [InverseProperty(""Posts"")] + [ForeignKey("PostsId")] + [InverseProperty("Posts")] public virtual ICollection Blogs { get; } = new List(); } -", +""", code.AdditionalFiles.Single(e => e.Path == "Post.cs")); Assert.Equal(2, code.AdditionalFiles.Count); diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpRuntimeModelCodeGeneratorTest.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpRuntimeModelCodeGeneratorTest.cs index 9adfe8c5cba..603cb8d6e12 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpRuntimeModelCodeGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpRuntimeModelCodeGeneratorTest.cs @@ -65,7 +65,8 @@ public void Empty_model() code, c => AssertFileContents( "EmptyContextModel.cs", - @"// +""" +// using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Scaffolding.Internal; @@ -94,11 +95,12 @@ static EmptyContextModel() partial void Customize(); } } -", +""", c), c => AssertFileContents( "EmptyContextModelBuilder.cs", - @"// +""" +// using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -114,7 +116,7 @@ partial void Initialize() } } } -", +""", c)), model => { @@ -545,7 +547,8 @@ public void Fully_qualified_model() code, c => AssertFileContents( "DbContextModel.cs", - @"// +""" +// using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Scaffolding.TestModel.Internal; @@ -574,11 +577,12 @@ static DbContextModel() partial void Customize(); } } -", +""", c), c => AssertFileContents( "DbContextModelBuilder.cs", - @"// +""" +// using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -604,11 +608,12 @@ partial void Initialize() } } } -", +""", c), c => AssertFileContents( "IndexEntityType.cs", - @"// +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore.Metadata; @@ -624,15 +629,15 @@ internal partial class IndexEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.Index"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.Index", typeof(Microsoft.EntityFrameworkCore.Scaffolding.Internal.Index), baseEntityType); var id = runtimeEntityType.AddProperty( - ""Id"", + "Id", typeof(Guid), - propertyInfo: typeof(Microsoft.EntityFrameworkCore.Scaffolding.Internal.Index).GetProperty(""Id"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Microsoft.EntityFrameworkCore.Scaffolding.Internal.Index).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(Microsoft.EntityFrameworkCore.Scaffolding.Internal.Index).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Microsoft.EntityFrameworkCore.Scaffolding.Internal.Index).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); @@ -652,12 +657,13 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", +""", c), c => AssertFileContents( "InternalEntityType.cs", - @"// +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore.Metadata; @@ -673,15 +679,15 @@ internal partial class InternalEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.Internal"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.Internal", typeof(Microsoft.EntityFrameworkCore.Scaffolding.Internal.Internal), baseEntityType); var id = runtimeEntityType.AddProperty( - ""Id"", + "Id", typeof(long), - propertyInfo: typeof(Microsoft.EntityFrameworkCore.Scaffolding.Internal.Internal).GetProperty(""Id"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Microsoft.EntityFrameworkCore.Scaffolding.Internal.Internal).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(Microsoft.EntityFrameworkCore.Scaffolding.Internal.Internal).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Microsoft.EntityFrameworkCore.Scaffolding.Internal.Internal).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); @@ -701,11 +707,12 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", +""", c), c => AssertFileContents( "IdentityUserEntityType.cs", - @"// +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore.Metadata; @@ -722,116 +729,116 @@ internal partial class IdentityUserEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.TestModels.AspNetIdentity.IdentityUser"", + "Microsoft.EntityFrameworkCore.TestModels.AspNetIdentity.IdentityUser", typeof(IdentityUser), baseEntityType, - discriminatorProperty: ""Discriminator"", - discriminatorValue: ""IdentityUser""); + discriminatorProperty: "Discriminator", + discriminatorValue: "IdentityUser"); var id = runtimeEntityType.AddProperty( - ""Id"", + "Id", typeof(string), - propertyInfo: typeof(IdentityUser).GetProperty(""Id"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(IdentityUser).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(IdentityUser).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), afterSaveBehavior: PropertySaveBehavior.Throw); var accessFailedCount = runtimeEntityType.AddProperty( - ""AccessFailedCount"", + "AccessFailedCount", typeof(int), - propertyInfo: typeof(IdentityUser).GetProperty(""AccessFailedCount"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(IdentityUser).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + propertyInfo: typeof(IdentityUser).GetProperty("AccessFailedCount", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var concurrencyStamp = runtimeEntityType.AddProperty( - ""ConcurrencyStamp"", + "ConcurrencyStamp", typeof(string), - propertyInfo: typeof(IdentityUser).GetProperty(""ConcurrencyStamp"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(IdentityUser).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(IdentityUser).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var discriminator = runtimeEntityType.AddProperty( - ""Discriminator"", + "Discriminator", typeof(string), afterSaveBehavior: PropertySaveBehavior.Throw, valueGeneratorFactory: new DiscriminatorValueGeneratorFactory().Create); var email = runtimeEntityType.AddProperty( - ""Email"", + "Email", typeof(string), - propertyInfo: typeof(IdentityUser).GetProperty(""Email"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(IdentityUser).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(IdentityUser).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var emailConfirmed = runtimeEntityType.AddProperty( - ""EmailConfirmed"", + "EmailConfirmed", typeof(bool), - propertyInfo: typeof(IdentityUser).GetProperty(""EmailConfirmed"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(IdentityUser).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + propertyInfo: typeof(IdentityUser).GetProperty("EmailConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var lockoutEnabled = runtimeEntityType.AddProperty( - ""LockoutEnabled"", + "LockoutEnabled", typeof(bool), - propertyInfo: typeof(IdentityUser).GetProperty(""LockoutEnabled"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(IdentityUser).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var lockoutEnd = runtimeEntityType.AddProperty( - ""LockoutEnd"", + "LockoutEnd", typeof(DateTimeOffset?), - propertyInfo: typeof(IdentityUser).GetProperty(""LockoutEnd"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(IdentityUser).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(IdentityUser).GetProperty("LockoutEnd", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var normalizedEmail = runtimeEntityType.AddProperty( - ""NormalizedEmail"", + "NormalizedEmail", typeof(string), - propertyInfo: typeof(IdentityUser).GetProperty(""NormalizedEmail"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(IdentityUser).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedEmail", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var normalizedUserName = runtimeEntityType.AddProperty( - ""NormalizedUserName"", + "NormalizedUserName", typeof(string), - propertyInfo: typeof(IdentityUser).GetProperty(""NormalizedUserName"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(IdentityUser).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(IdentityUser).GetProperty("NormalizedUserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var passwordHash = runtimeEntityType.AddProperty( - ""PasswordHash"", + "PasswordHash", typeof(string), - propertyInfo: typeof(IdentityUser).GetProperty(""PasswordHash"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(IdentityUser).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(IdentityUser).GetProperty("PasswordHash", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var phoneNumber = runtimeEntityType.AddProperty( - ""PhoneNumber"", + "PhoneNumber", typeof(string), - propertyInfo: typeof(IdentityUser).GetProperty(""PhoneNumber"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(IdentityUser).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var phoneNumberConfirmed = runtimeEntityType.AddProperty( - ""PhoneNumberConfirmed"", + "PhoneNumberConfirmed", typeof(bool), - propertyInfo: typeof(IdentityUser).GetProperty(""PhoneNumberConfirmed"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(IdentityUser).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + propertyInfo: typeof(IdentityUser).GetProperty("PhoneNumberConfirmed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var securityStamp = runtimeEntityType.AddProperty( - ""SecurityStamp"", + "SecurityStamp", typeof(string), - propertyInfo: typeof(IdentityUser).GetProperty(""SecurityStamp"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(IdentityUser).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(IdentityUser).GetProperty("SecurityStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var twoFactorEnabled = runtimeEntityType.AddProperty( - ""TwoFactorEnabled"", + "TwoFactorEnabled", typeof(bool), - propertyInfo: typeof(IdentityUser).GetProperty(""TwoFactorEnabled"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(IdentityUser).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + propertyInfo: typeof(IdentityUser).GetProperty("TwoFactorEnabled", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var userName = runtimeEntityType.AddProperty( - ""UserName"", + "UserName", typeof(string), - propertyInfo: typeof(IdentityUser).GetProperty(""UserName"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(IdentityUser).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(IdentityUser).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(IdentityUser).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var key = runtimeEntityType.AddKey( @@ -850,12 +857,13 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", +""", c), c => AssertFileContents( "IdentityUser0EntityType.cs", - @"// +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore.Metadata; @@ -871,11 +879,11 @@ internal partial class IdentityUser0EntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.IdentityUser"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.IdentityUser", typeof(IdentityUser), baseEntityType, - discriminatorProperty: ""Discriminator"", - discriminatorValue: ""DerivedIdentityUser""); + discriminatorProperty: "Discriminator", + discriminatorValue: "DerivedIdentityUser"); return runtimeEntityType; } @@ -889,7 +897,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", +""", c)), model => { @@ -931,7 +939,8 @@ public void BigModel() code, c => AssertFileContents( "BigContextModel.cs", - @"// +""" +// using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Scaffolding.Internal; @@ -960,10 +969,11 @@ static BigContextModel() partial void Customize(); } } -", c), +""", c), c => AssertFileContents( "BigContextModelBuilder.cs", - @"// +""" +// using System; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -1005,14 +1015,16 @@ partial void Initialize() DependentDerivedEntityType.CreateAnnotations(dependentDerived); PrincipalDerivedEntityType.CreateAnnotations(principalDerived); - AddAnnotation(""Relational:MaxIdentifierLength"", 128); - AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn); + AddAnnotation("Relational:MaxIdentifierLength", 128); + AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); } } } -", c), +""", c), c => AssertFileContents( - "DependentBaseEntityType.cs", @"// + "DependentBaseEntityType.cs", +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore; @@ -1031,38 +1043,38 @@ internal partial class DependentBaseEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DependentBase"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DependentBase", typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase), baseEntityType, - discriminatorProperty: ""EnumDiscriminator"", + discriminatorProperty: "EnumDiscriminator", discriminatorValue: CSharpMigrationsGeneratorTest.Enum1.One); var principalId = runtimeEntityType.AddProperty( - ""PrincipalId"", + "PrincipalId", typeof(long), afterSaveBehavior: PropertySaveBehavior.Throw); - principalId.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + principalId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var principalAlternateId = runtimeEntityType.AddProperty( - ""PrincipalAlternateId"", + "PrincipalAlternateId", typeof(Guid), afterSaveBehavior: PropertySaveBehavior.Throw); - principalAlternateId.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + principalAlternateId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var enumDiscriminator = runtimeEntityType.AddProperty( - ""EnumDiscriminator"", + "EnumDiscriminator", typeof(CSharpMigrationsGeneratorTest.Enum1), afterSaveBehavior: PropertySaveBehavior.Throw, valueGeneratorFactory: new DiscriminatorValueGeneratorFactory().Create); - enumDiscriminator.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + enumDiscriminator.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var id = runtimeEntityType.AddProperty( - ""Id"", + "Id", typeof(byte?), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetProperty(""Id"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetProperty("Id", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); - id.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + id.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var key = runtimeEntityType.AddKey( new[] { principalId, principalAlternateId }); @@ -1077,8 +1089,8 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? ba public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty(""PrincipalId"")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty(""Id"")! })!, + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PrincipalId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, principalEntityType, deleteBehavior: DeleteBehavior.Cascade, unique: true, @@ -1089,26 +1101,26 @@ public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEnt public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty(""PrincipalId"")!, declaringEntityType.FindProperty(""PrincipalAlternateId"")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty(""Id"")!, principalEntityType.FindProperty(""AlternateId"")! })!, + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PrincipalId")!, declaringEntityType.FindProperty("PrincipalAlternateId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")!, principalEntityType.FindProperty("AlternateId")! })!, principalEntityType, deleteBehavior: DeleteBehavior.ClientNoAction, unique: true, required: true); - var principal = declaringEntityType.AddNavigation(""Principal"", + var principal = declaringEntityType.AddNavigation("Principal", runtimeForeignKey, onDependent: true, typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetProperty(""Principal"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetProperty("Principal", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); - var dependent = principalEntityType.AddNavigation(""Dependent"", + var dependent = principalEntityType.AddNavigation("Dependent", runtimeForeignKey, onDependent: false, typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetProperty(""Dependent"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetProperty("Dependent", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), eagerLoaded: true, lazyLoadingEnabled: false); @@ -1117,14 +1129,14 @@ public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEnt public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { - runtimeEntityType.AddAnnotation(""DiscriminatorMappingComplete"", false); - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", null); - runtimeEntityType.AddAnnotation(""Relational:MappingStrategy"", ""TPH""); - runtimeEntityType.AddAnnotation(""Relational:Schema"", null); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", ""DependentBase""); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", null); + runtimeEntityType.AddAnnotation("DiscriminatorMappingComplete", false); + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:MappingStrategy", "TPH"); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DependentBase"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); Customize(runtimeEntityType); } @@ -1132,9 +1144,11 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", c), +""", c), c => AssertFileContents( - "PrincipalBaseEntityType.cs", @"// + "PrincipalBaseEntityType.cs", +""" +// using System; using System.Collections.Generic; using System.Reflection; @@ -1154,49 +1168,49 @@ internal partial class PrincipalBaseEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+PrincipalBase"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+PrincipalBase", typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase), baseEntityType, - discriminatorValue: ""PrincipalBase""); + discriminatorValue: "PrincipalBase"); var id = runtimeEntityType.AddProperty( - ""Id"", + "Id", typeof(long?), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetProperty(""Id"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); var overrides = new StoreObjectDictionary(); var idPrincipalDerived = new RuntimeRelationalPropertyOverrides( id, - StoreObjectIdentifier.Table(""PrincipalDerived"", null), + StoreObjectIdentifier.Table("PrincipalDerived", null), true, - ""DerivedId""); - overrides.Add(StoreObjectIdentifier.Table(""PrincipalDerived"", null), idPrincipalDerived); - id.AddAnnotation(""Relational:RelationalOverrides"", overrides); + "DerivedId"); + overrides.Add(StoreObjectIdentifier.Table("PrincipalDerived", null), idPrincipalDerived); + id.AddAnnotation("Relational:RelationalOverrides", overrides); - id.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn); + id.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); var alternateId = runtimeEntityType.AddProperty( - ""AlternateId"", + "AlternateId", typeof(Guid), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetField(""AlternateId"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetField("AlternateId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), propertyAccessMode: PropertyAccessMode.FieldDuringConstruction, afterSaveBehavior: PropertySaveBehavior.Throw); - alternateId.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + alternateId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var point = runtimeEntityType.AddProperty( - ""Point"", + "Point", typeof(Point), nullable: true, valueGenerated: ValueGenerated.OnAdd, valueConverter: new CastingConverter(), valueComparer: new CSharpRuntimeModelCodeGeneratorTest.CustomValueComparer(), providerValueComparer: new CSharpRuntimeModelCodeGeneratorTest.CustomValueComparer()); - point.AddAnnotation(""Relational:ColumnType"", ""geometry""); - point.AddAnnotation(""Relational:DefaultValue"", (NetTopologySuite.Geometries.Point)new NetTopologySuite.IO.WKTReader().Read(""SRID=0;POINT Z(0 0 0)"")); - point.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + point.AddAnnotation("Relational:ColumnType", "geometry"); + point.AddAnnotation("Relational:DefaultValue", (NetTopologySuite.Geometries.Point)new NetTopologySuite.IO.WKTReader().Read("SRID=0;POINT Z(0 0 0)")); + point.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var key = runtimeEntityType.AddKey( new[] { id }); @@ -1204,7 +1218,7 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? ba var key0 = runtimeEntityType.AddKey( new[] { id, alternateId }); runtimeEntityType.SetPrimaryKey(key0); - key0.AddAnnotation(""Relational:Name"", ""PK""); + key0.AddAnnotation("Relational:Name", "PK"); var index = runtimeEntityType.AddIndex( new[] { alternateId, id }); @@ -1215,19 +1229,19 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? ba public static RuntimeSkipNavigation CreateSkipNavigation1(RuntimeEntityType declaringEntityType, RuntimeEntityType targetEntityType, RuntimeEntityType joinEntityType) { var skipNavigation = declaringEntityType.AddSkipNavigation( - ""Deriveds"", + "Deriveds", targetEntityType, joinEntityType.FindForeignKey( - new[] { joinEntityType.FindProperty(""PrincipalsId"")!, joinEntityType.FindProperty(""PrincipalsAlternateId"")! }, - declaringEntityType.FindKey(new[] { declaringEntityType.FindProperty(""Id"")!, declaringEntityType.FindProperty(""AlternateId"")! })!, + new[] { joinEntityType.FindProperty("PrincipalsId")!, joinEntityType.FindProperty("PrincipalsAlternateId")! }, + declaringEntityType.FindKey(new[] { declaringEntityType.FindProperty("Id")!, declaringEntityType.FindProperty("AlternateId")! })!, declaringEntityType)!, true, false, typeof(ICollection), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetProperty(""Deriveds"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetProperty("Deriveds", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); - var inverse = targetEntityType.FindSkipNavigation(""Principals""); + var inverse = targetEntityType.FindSkipNavigation("Principals"); if (inverse != null) { skipNavigation.Inverse = inverse; @@ -1239,13 +1253,13 @@ public static RuntimeSkipNavigation CreateSkipNavigation1(RuntimeEntityType decl public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", null); - runtimeEntityType.AddAnnotation(""Relational:MappingStrategy"", ""TPT""); - runtimeEntityType.AddAnnotation(""Relational:Schema"", ""mySchema""); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", ""PrincipalBase""); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", null); + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:MappingStrategy", "TPT"); + runtimeEntityType.AddAnnotation("Relational:Schema", "mySchema"); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PrincipalBase"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); Customize(runtimeEntityType); } @@ -1253,9 +1267,11 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", c), +""", c), c => AssertFileContents( - "OwnedTypeEntityType.cs", @"// + "OwnedTypeEntityType.cs", +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore; @@ -1272,14 +1288,14 @@ internal partial class OwnedTypeEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+PrincipalBase.Owned#OwnedType"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+PrincipalBase.Owned#OwnedType", typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType), baseEntityType, sharedClrType: true, changeTrackingStrategy: ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues); var principalBaseId = runtimeEntityType.AddProperty( - ""PrincipalBaseId"", + "PrincipalBaseId", typeof(long), propertyAccessMode: PropertyAccessMode.Field, valueGenerated: ValueGenerated.OnAdd, @@ -1288,53 +1304,53 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? ba var overrides = new StoreObjectDictionary(); var principalBaseIdPrincipalBase = new RuntimeRelationalPropertyOverrides( principalBaseId, - StoreObjectIdentifier.Table(""PrincipalBase"", ""mySchema""), + StoreObjectIdentifier.Table("PrincipalBase", "mySchema"), false, null); - principalBaseIdPrincipalBase.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn); - overrides.Add(StoreObjectIdentifier.Table(""PrincipalBase"", ""mySchema""), principalBaseIdPrincipalBase); - principalBaseId.AddAnnotation(""Relational:RelationalOverrides"", overrides); + principalBaseIdPrincipalBase.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + overrides.Add(StoreObjectIdentifier.Table("PrincipalBase", "mySchema"), principalBaseIdPrincipalBase); + principalBaseId.AddAnnotation("Relational:RelationalOverrides", overrides); - principalBaseId.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn); + principalBaseId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); var principalBaseAlternateId = runtimeEntityType.AddProperty( - ""PrincipalBaseAlternateId"", + "PrincipalBaseAlternateId", typeof(Guid), propertyAccessMode: PropertyAccessMode.Field, afterSaveBehavior: PropertySaveBehavior.Throw); - principalBaseAlternateId.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + principalBaseAlternateId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var details = runtimeEntityType.AddProperty( - ""Details"", + "Details", typeof(string), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetProperty(""Details"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetField(""
k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetProperty("Details", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetField("
k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), propertyAccessMode: PropertyAccessMode.Field, nullable: true); var overrides0 = new StoreObjectDictionary(); var detailsDetails = new RuntimeRelationalPropertyOverrides( details, - StoreObjectIdentifier.Table(""Details"", null), + StoreObjectIdentifier.Table("Details", null), false, null); - overrides0.Add(StoreObjectIdentifier.Table(""Details"", null), detailsDetails); - details.AddAnnotation(""Relational:RelationalOverrides"", overrides0); + overrides0.Add(StoreObjectIdentifier.Table("Details", null), detailsDetails); + details.AddAnnotation("Relational:RelationalOverrides", overrides0); - details.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + details.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var number = runtimeEntityType.AddProperty( - ""Number"", + "Number", typeof(int), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetProperty(""Number"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetProperty("Number", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), propertyAccessMode: PropertyAccessMode.Field); - number.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + number.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var context = runtimeEntityType.AddServiceProperty( - ""Context"", + "Context", typeof(Microsoft.EntityFrameworkCore.DbContext), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetProperty(""Context"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetProperty("Context", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var key = runtimeEntityType.AddKey( new[] { principalBaseId, principalBaseAlternateId }); @@ -1345,8 +1361,8 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? ba public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty(""PrincipalBaseId"")!, declaringEntityType.FindProperty(""PrincipalBaseAlternateId"")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty(""Id"")!, principalEntityType.FindProperty(""AlternateId"")! })!, + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PrincipalBaseId")!, declaringEntityType.FindProperty("PrincipalBaseAlternateId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")!, principalEntityType.FindProperty("AlternateId")! })!, principalEntityType, deleteBehavior: DeleteBehavior.Cascade, unique: true, @@ -1354,12 +1370,12 @@ public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEnt requiredDependent: true, ownership: true); - var owned = principalEntityType.AddNavigation(""Owned"", + var owned = principalEntityType.AddNavigation("Owned", runtimeForeignKey, onDependent: false, typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetProperty(""Owned"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetField(""_ownedField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetProperty("Owned", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetField("_ownedField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), propertyAccessMode: PropertyAccessMode.Field, eagerLoaded: true); @@ -1368,8 +1384,8 @@ public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEnt public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty(""PrincipalBaseId"")!, declaringEntityType.FindProperty(""PrincipalBaseAlternateId"")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty(""PrincipalBaseId"")!, principalEntityType.FindProperty(""PrincipalBaseAlternateId"")! })!, + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PrincipalBaseId")!, declaringEntityType.FindProperty("PrincipalBaseAlternateId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("PrincipalBaseId")!, principalEntityType.FindProperty("PrincipalBaseAlternateId")! })!, principalEntityType, deleteBehavior: DeleteBehavior.Cascade, unique: true, @@ -1384,16 +1400,16 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) var fragments = new StoreObjectDictionary(); var detailsFragment = new RuntimeEntityTypeMappingFragment( runtimeEntityType, - StoreObjectIdentifier.Table(""Details"", null), + StoreObjectIdentifier.Table("Details", null), null); - fragments.Add(StoreObjectIdentifier.Table(""Details"", null), detailsFragment); - runtimeEntityType.AddAnnotation(""Relational:MappingFragments"", fragments); - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", null); - runtimeEntityType.AddAnnotation(""Relational:Schema"", ""mySchema""); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", ""PrincipalBase""); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", null); + fragments.Add(StoreObjectIdentifier.Table("Details", null), detailsFragment); + runtimeEntityType.AddAnnotation("Relational:MappingFragments", fragments); + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", "mySchema"); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PrincipalBase"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); Customize(runtimeEntityType); } @@ -1401,9 +1417,11 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", c), +""", c), c => AssertFileContents( - "OwnedType0EntityType.cs", @"// + "OwnedType0EntityType.cs", +""" +// using System; using System.Collections.Generic; using System.Reflection; @@ -1421,49 +1439,49 @@ internal partial class OwnedType0EntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+PrincipalDerived>.ManyOwned#OwnedType"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+PrincipalDerived>.ManyOwned#OwnedType", typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType), baseEntityType, sharedClrType: true); var principalDerivedId = runtimeEntityType.AddProperty( - ""PrincipalDerivedId"", + "PrincipalDerivedId", typeof(long), afterSaveBehavior: PropertySaveBehavior.Throw); - principalDerivedId.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + principalDerivedId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var principalDerivedAlternateId = runtimeEntityType.AddProperty( - ""PrincipalDerivedAlternateId"", + "PrincipalDerivedAlternateId", typeof(Guid), afterSaveBehavior: PropertySaveBehavior.Throw); - principalDerivedAlternateId.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + principalDerivedAlternateId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var id = runtimeEntityType.AddProperty( - ""Id"", + "Id", typeof(int), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); - id.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn); + id.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); var details = runtimeEntityType.AddProperty( - ""Details"", + "Details", typeof(string), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetProperty(""Details"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetField(""
k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetProperty("Details", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetField("
k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); - details.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + details.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var number = runtimeEntityType.AddProperty( - ""Number"", + "Number", typeof(int), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetProperty(""Number"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); - number.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetProperty("Number", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + number.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var context = runtimeEntityType.AddServiceProperty( - ""Context"", + "Context", typeof(Microsoft.EntityFrameworkCore.DbContext), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetProperty(""Context"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.OwnedType).GetProperty("Context", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var key = runtimeEntityType.AddKey( new[] { principalDerivedId, principalDerivedAlternateId, id }); @@ -1474,18 +1492,18 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? ba public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty(""PrincipalDerivedId"")!, declaringEntityType.FindProperty(""PrincipalDerivedAlternateId"")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty(""Id"")!, principalEntityType.FindProperty(""AlternateId"")! })!, + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PrincipalDerivedId")!, declaringEntityType.FindProperty("PrincipalDerivedAlternateId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")!, principalEntityType.FindProperty("AlternateId")! })!, principalEntityType, deleteBehavior: DeleteBehavior.Cascade, required: true, ownership: true); - var manyOwned = principalEntityType.AddNavigation(""ManyOwned"", + var manyOwned = principalEntityType.AddNavigation("ManyOwned", runtimeForeignKey, onDependent: false, typeof(ICollection), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetField(""ManyOwned"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetField("ManyOwned", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), eagerLoaded: true); return runtimeForeignKey; @@ -1493,13 +1511,13 @@ public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEnt public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", null); - runtimeEntityType.AddAnnotation(""Relational:Schema"", null); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", ""ManyOwned""); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", null); - runtimeEntityType.AddAnnotation(""SqlServer:MemoryOptimized"", true); + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "ManyOwned"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + runtimeEntityType.AddAnnotation("SqlServer:MemoryOptimized", true); Customize(runtimeEntityType); } @@ -1507,9 +1525,11 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", c), +""", c), c => AssertFileContents( - "PrincipalBasePrincipalDerivedDependentBasebyteEntityType.cs", @"// + "PrincipalBasePrincipalDerivedDependentBasebyteEntityType.cs", +""" +// using System; using System.Collections.Generic; using System.Reflection; @@ -1526,7 +1546,7 @@ internal partial class PrincipalBasePrincipalDerivedDependentBasebyteEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""PrincipalBasePrincipalDerived>"", + "PrincipalBasePrincipalDerived>", typeof(Dictionary), baseEntityType, sharedClrType: true, @@ -1534,35 +1554,35 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? ba propertyBag: true); var derivedsId = runtimeEntityType.AddProperty( - ""DerivedsId"", + "DerivedsId", typeof(long), propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(), afterSaveBehavior: PropertySaveBehavior.Throw); - derivedsId.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + derivedsId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var derivedsAlternateId = runtimeEntityType.AddProperty( - ""DerivedsAlternateId"", + "DerivedsAlternateId", typeof(Guid), propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(), afterSaveBehavior: PropertySaveBehavior.Throw); - derivedsAlternateId.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + derivedsAlternateId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var principalsId = runtimeEntityType.AddProperty( - ""PrincipalsId"", + "PrincipalsId", typeof(long), propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(), afterSaveBehavior: PropertySaveBehavior.Throw); - principalsId.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + principalsId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var principalsAlternateId = runtimeEntityType.AddProperty( - ""PrincipalsAlternateId"", + "PrincipalsAlternateId", typeof(Guid), propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(), afterSaveBehavior: PropertySaveBehavior.Throw); - principalsAlternateId.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + principalsAlternateId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var rowid = runtimeEntityType.AddProperty( - ""rowid"", + "rowid", typeof(byte[]), propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(), nullable: true, @@ -1570,7 +1590,7 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? ba valueGenerated: ValueGenerated.OnAddOrUpdate, beforeSaveBehavior: PropertySaveBehavior.Ignore, afterSaveBehavior: PropertySaveBehavior.Ignore); - rowid.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + rowid.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var key = runtimeEntityType.AddKey( new[] { derivedsId, derivedsAlternateId, principalsId, principalsAlternateId }); @@ -1584,8 +1604,8 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? ba public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty(""DerivedsId"")!, declaringEntityType.FindProperty(""DerivedsAlternateId"")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty(""Id"")!, principalEntityType.FindProperty(""AlternateId"")! })!, + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DerivedsId")!, declaringEntityType.FindProperty("DerivedsAlternateId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")!, principalEntityType.FindProperty("AlternateId")! })!, principalEntityType, deleteBehavior: DeleteBehavior.Cascade, required: true); @@ -1595,8 +1615,8 @@ public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEnt public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty(""PrincipalsId"")!, declaringEntityType.FindProperty(""PrincipalsAlternateId"")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty(""Id"")!, principalEntityType.FindProperty(""AlternateId"")! })!, + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PrincipalsId")!, declaringEntityType.FindProperty("PrincipalsAlternateId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")!, principalEntityType.FindProperty("AlternateId")! })!, principalEntityType, deleteBehavior: DeleteBehavior.ClientCascade, required: true); @@ -1606,12 +1626,12 @@ public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEnt public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", null); - runtimeEntityType.AddAnnotation(""Relational:Schema"", null); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", ""PrincipalBasePrincipalDerived>""); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", null); + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PrincipalBasePrincipalDerived>"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); Customize(runtimeEntityType); } @@ -1619,9 +1639,11 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", c), +""", c), c => AssertFileContents( - "DependentDerivedEntityType.cs", @"// + "DependentDerivedEntityType.cs", +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore.Metadata; @@ -1638,41 +1660,41 @@ internal partial class DependentDerivedEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DependentDerived"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DependentDerived", typeof(CSharpRuntimeModelCodeGeneratorTest.DependentDerived), baseEntityType, - discriminatorProperty: ""EnumDiscriminator"", + discriminatorProperty: "EnumDiscriminator", discriminatorValue: CSharpMigrationsGeneratorTest.Enum1.Two); var data = runtimeEntityType.AddProperty( - ""Data"", + "Data", typeof(string), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentDerived).GetProperty(""Data"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentDerived).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentDerived).GetProperty("Data", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentDerived).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true, maxLength: 20, unicode: false); - data.AddAnnotation(""Relational:IsFixedLength"", true); - data.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + data.AddAnnotation("Relational:IsFixedLength", true); + data.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var money = runtimeEntityType.AddProperty( - ""Money"", + "Money", typeof(decimal), precision: 9, scale: 3); - money.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + money.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); return runtimeEntityType; } public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", null); - runtimeEntityType.AddAnnotation(""Relational:Schema"", null); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", ""DependentBase""); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", null); + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DependentBase"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); Customize(runtimeEntityType); } @@ -1680,9 +1702,11 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", c), +""", c), c => AssertFileContents( - "PrincipalDerivedEntityType.cs", @"// + "PrincipalDerivedEntityType.cs", +""" +// using System; using System.Collections.Generic; using System.Reflection; @@ -1700,18 +1724,18 @@ internal partial class PrincipalDerivedEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+PrincipalDerived>"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+PrincipalDerived>", typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>), baseEntityType, - discriminatorValue: ""PrincipalDerived>""); + discriminatorValue: "PrincipalDerived>"); return runtimeEntityType; } public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty(""Id"")!, declaringEntityType.FindProperty(""AlternateId"")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty(""Id"")!, principalEntityType.FindProperty(""AlternateId"")! })!, + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("Id")!, declaringEntityType.FindProperty("AlternateId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")!, principalEntityType.FindProperty("AlternateId")! })!, principalEntityType, deleteBehavior: DeleteBehavior.Cascade, unique: true, @@ -1723,21 +1747,21 @@ public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEnt public static RuntimeSkipNavigation CreateSkipNavigation1(RuntimeEntityType declaringEntityType, RuntimeEntityType targetEntityType, RuntimeEntityType joinEntityType) { var skipNavigation = declaringEntityType.AddSkipNavigation( - ""Principals"", + "Principals", targetEntityType, joinEntityType.FindForeignKey( - new[] { joinEntityType.FindProperty(""DerivedsId"")!, joinEntityType.FindProperty(""DerivedsAlternateId"")! }, - declaringEntityType.FindKey(new[] { declaringEntityType.FindProperty(""Id"")!, declaringEntityType.FindProperty(""AlternateId"")! })!, + new[] { joinEntityType.FindProperty("DerivedsId")!, joinEntityType.FindProperty("DerivedsAlternateId")! }, + declaringEntityType.FindKey(new[] { declaringEntityType.FindProperty("Id")!, declaringEntityType.FindProperty("AlternateId")! })!, declaringEntityType)!, true, false, typeof(ICollection), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetProperty(""Principals"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetProperty("Principals", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), eagerLoaded: true, lazyLoadingEnabled: false); - var inverse = targetEntityType.FindSkipNavigation(""Deriveds""); + var inverse = targetEntityType.FindSkipNavigation("Deriveds"); if (inverse != null) { skipNavigation.Inverse = inverse; @@ -1749,12 +1773,12 @@ public static RuntimeSkipNavigation CreateSkipNavigation1(RuntimeEntityType decl public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", null); - runtimeEntityType.AddAnnotation(""Relational:Schema"", null); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", ""PrincipalDerived""); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", null); + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PrincipalDerived"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); Customize(runtimeEntityType); } @@ -1762,7 +1786,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", c)), +""", c)), model => { Assert.Equal( @@ -2357,7 +2381,8 @@ public void TPC_model() code, c => AssertFileContents( "TpcContextModel.cs", - @"// +""" +// using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Scaffolding.Internal; @@ -2386,10 +2411,11 @@ static TpcContextModel() partial void Customize(); } } -", c), +""", c), c => AssertFileContents( "TpcContextModelBuilder.cs", - @"// +""" +// using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -2418,24 +2444,26 @@ partial void Initialize() var sequences = new SortedDictionary<(string, string?), ISequence>(); var principalBaseSequence = new RuntimeSequence( - ""PrincipalBaseSequence"", + "PrincipalBaseSequence", this, typeof(long), - schema: ""TPC"", + schema: "TPC", modelSchemaIsNull: true); - sequences[(""PrincipalBaseSequence"", null)] = principalBaseSequence; + sequences[("PrincipalBaseSequence", null)] = principalBaseSequence; - AddAnnotation(""Relational:Sequences"", sequences); - AddAnnotation(""Relational:DefaultSchema"", ""TPC""); - AddAnnotation(""Relational:MaxIdentifierLength"", 128); - AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn); + AddAnnotation("Relational:Sequences", sequences); + AddAnnotation("Relational:DefaultSchema", "TPC"); + AddAnnotation("Relational:MaxIdentifierLength", 128); + AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); } } } -", c), +""", c), c => AssertFileContents( - "DependentBaseEntityType.cs", @"// + "DependentBaseEntityType.cs", +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore; @@ -2452,23 +2480,23 @@ internal partial class DependentBaseEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DependentBase"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DependentBase", typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase), baseEntityType); var id = runtimeEntityType.AddProperty( - ""Id"", + "Id", typeof(byte?), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetProperty(""Id"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetProperty("Id", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), afterSaveBehavior: PropertySaveBehavior.Throw); - id.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + id.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var principalId = runtimeEntityType.AddProperty( - ""PrincipalId"", + "PrincipalId", typeof(long?), nullable: true); - principalId.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + principalId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var key = runtimeEntityType.AddKey( new[] { id }); @@ -2483,38 +2511,38 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? ba public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty(""PrincipalId"")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty(""Id"")! })!, + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PrincipalId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, principalEntityType, deleteBehavior: DeleteBehavior.ClientCascade, unique: true, requiredDependent: true); - var principal = declaringEntityType.AddNavigation(""Principal"", + var principal = declaringEntityType.AddNavigation("Principal", runtimeForeignKey, onDependent: true, typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetProperty(""Principal"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetProperty("Principal", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); - var dependent = principalEntityType.AddNavigation(""Dependent"", + var dependent = principalEntityType.AddNavigation("Dependent", runtimeForeignKey, onDependent: false, typeof(CSharpRuntimeModelCodeGeneratorTest.DependentBase), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetProperty(""Dependent"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetProperty("Dependent", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); return runtimeForeignKey; } public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", null); - runtimeEntityType.AddAnnotation(""Relational:Schema"", ""TPC""); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", ""DependentBase""); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", null); + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", "TPC"); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "DependentBase"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); Customize(runtimeEntityType); } @@ -2522,9 +2550,11 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", c), +""", c), c => AssertFileContents( - "PrincipalBaseEntityType.cs", @"// + "PrincipalBaseEntityType.cs", +""" +// using System; using System.Collections.Generic; using System.Data; @@ -2542,49 +2572,49 @@ internal partial class PrincipalBaseEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+PrincipalBase"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+PrincipalBase", typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase), baseEntityType, - discriminatorValue: ""PrincipalBase""); + discriminatorValue: "PrincipalBase"); var id = runtimeEntityType.AddProperty( - ""Id"", + "Id", typeof(long?), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetProperty(""Id"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); var overrides = new StoreObjectDictionary(); var idDerived_Insert = new RuntimeRelationalPropertyOverrides( id, - StoreObjectIdentifier.InsertStoredProcedure(""Derived_Insert"", ""TPC""), + StoreObjectIdentifier.InsertStoredProcedure("Derived_Insert", "TPC"), true, - ""DerivedId""); - overrides.Add(StoreObjectIdentifier.InsertStoredProcedure(""Derived_Insert"", ""TPC""), idDerived_Insert); + "DerivedId"); + overrides.Add(StoreObjectIdentifier.InsertStoredProcedure("Derived_Insert", "TPC"), idDerived_Insert); var idPrincipalBaseView = new RuntimeRelationalPropertyOverrides( id, - StoreObjectIdentifier.View(""PrincipalBaseView"", ""TPC""), + StoreObjectIdentifier.View("PrincipalBaseView", "TPC"), false, null); - idPrincipalBaseView.AddAnnotation(""foo"", ""bar2""); - overrides.Add(StoreObjectIdentifier.View(""PrincipalBaseView"", ""TPC""), idPrincipalBaseView); - id.AddAnnotation(""Relational:RelationalOverrides"", overrides); + idPrincipalBaseView.AddAnnotation("foo", "bar2"); + overrides.Add(StoreObjectIdentifier.View("PrincipalBaseView", "TPC"), idPrincipalBaseView); + id.AddAnnotation("Relational:RelationalOverrides", overrides); - id.AddAnnotation(""Relational:DefaultValueSql"", ""NEXT VALUE FOR [TPC].[PrincipalBaseSequence]""); - id.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.Sequence); + id.AddAnnotation("Relational:DefaultValueSql", "NEXT VALUE FOR [TPC].[PrincipalBaseSequence]"); + id.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.Sequence); var principalBaseId = runtimeEntityType.AddProperty( - ""PrincipalBaseId"", + "PrincipalBaseId", typeof(long?), nullable: true); - principalBaseId.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + principalBaseId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var principalDerivedId = runtimeEntityType.AddProperty( - ""PrincipalDerivedId"", + "PrincipalDerivedId", typeof(long?), nullable: true); - principalDerivedId.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + principalDerivedId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var key = runtimeEntityType.AddKey( new[] { id }); @@ -2595,41 +2625,41 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? ba var principalIndex = runtimeEntityType.AddIndex( new[] { principalBaseId }, - name: ""PrincipalIndex"", + name: "PrincipalIndex", unique: true); - principalIndex.AddAnnotation(""Relational:Name"", ""PIX""); + principalIndex.AddAnnotation("Relational:Name", "PIX"); return runtimeEntityType; } public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty(""PrincipalBaseId"")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty(""Id"")! })!, + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PrincipalBaseId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, principalEntityType); - var deriveds = principalEntityType.AddNavigation(""Deriveds"", + var deriveds = principalEntityType.AddNavigation("Deriveds", runtimeForeignKey, onDependent: false, typeof(ICollection), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetProperty(""Deriveds"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetProperty("Deriveds", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalBase).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); return runtimeForeignKey; } public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty(""PrincipalDerivedId"")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty(""Id"")! })!, + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PrincipalDerivedId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, principalEntityType); - var principals = principalEntityType.AddNavigation(""Principals"", + var principals = principalEntityType.AddNavigation("Principals", runtimeForeignKey, onDependent: false, typeof(ICollection), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetProperty(""Principals"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetProperty("Principals", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); return runtimeForeignKey; } @@ -2638,52 +2668,52 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { var insertSproc = new RuntimeStoredProcedure( runtimeEntityType, - ""PrincipalBase_Insert"", - ""TPC"", + "PrincipalBase_Insert", + "TPC", false); var principalBaseId = insertSproc.AddParameter( - ""PrincipalBaseId"", ParameterDirection.Input, false, ""PrincipalBaseId"", false); + "PrincipalBaseId", ParameterDirection.Input, false, "PrincipalBaseId", false); var principalDerivedId = insertSproc.AddParameter( - ""PrincipalDerivedId"", ParameterDirection.Input, false, ""PrincipalDerivedId"", false); + "PrincipalDerivedId", ParameterDirection.Input, false, "PrincipalDerivedId", false); var id = insertSproc.AddParameter( - ""BaseId"", ParameterDirection.Output, false, ""Id"", false); - id.AddAnnotation(""foo"", ""bar""); - insertSproc.AddAnnotation(""foo"", ""bar1""); - runtimeEntityType.AddAnnotation(""Relational:InsertStoredProcedure"", insertSproc); + "BaseId", ParameterDirection.Output, false, "Id", false); + id.AddAnnotation("foo", "bar"); + insertSproc.AddAnnotation("foo", "bar1"); + runtimeEntityType.AddAnnotation("Relational:InsertStoredProcedure", insertSproc); var deleteSproc = new RuntimeStoredProcedure( runtimeEntityType, - ""PrincipalBase_Delete"", - ""TPC"", + "PrincipalBase_Delete", + "TPC", true); var id0 = deleteSproc.AddParameter( - ""Id_Original"", ParameterDirection.Input, false, ""Id"", true); - runtimeEntityType.AddAnnotation(""Relational:DeleteStoredProcedure"", deleteSproc); + "Id_Original", ParameterDirection.Input, false, "Id", true); + runtimeEntityType.AddAnnotation("Relational:DeleteStoredProcedure", deleteSproc); var updateSproc = new RuntimeStoredProcedure( runtimeEntityType, - ""PrincipalBase_Update"", - ""TPC"", + "PrincipalBase_Update", + "TPC", false); var principalBaseId0 = updateSproc.AddParameter( - ""PrincipalBaseId"", ParameterDirection.Input, false, ""PrincipalBaseId"", false); + "PrincipalBaseId", ParameterDirection.Input, false, "PrincipalBaseId", false); var principalDerivedId0 = updateSproc.AddParameter( - ""PrincipalDerivedId"", ParameterDirection.Input, false, ""PrincipalDerivedId"", false); + "PrincipalDerivedId", ParameterDirection.Input, false, "PrincipalDerivedId", false); var id1 = updateSproc.AddParameter( - ""Id_Original"", ParameterDirection.Input, false, ""Id"", true); - runtimeEntityType.AddAnnotation(""Relational:UpdateStoredProcedure"", updateSproc); - - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", null); - runtimeEntityType.AddAnnotation(""Relational:MappingStrategy"", ""TPC""); - runtimeEntityType.AddAnnotation(""Relational:Schema"", ""TPC""); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", ""PrincipalBase""); - runtimeEntityType.AddAnnotation(""Relational:ViewDefinitionSql"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", ""PrincipalBaseView""); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", ""TPC""); + "Id_Original", ParameterDirection.Input, false, "Id", true); + runtimeEntityType.AddAnnotation("Relational:UpdateStoredProcedure", updateSproc); + + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:MappingStrategy", "TPC"); + runtimeEntityType.AddAnnotation("Relational:Schema", "TPC"); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PrincipalBase"); + runtimeEntityType.AddAnnotation("Relational:ViewDefinitionSql", null); + runtimeEntityType.AddAnnotation("Relational:ViewName", "PrincipalBaseView"); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", "TPC"); Customize(runtimeEntityType); } @@ -2691,9 +2721,11 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", c), +""", c), c => AssertFileContents( - "PrincipalDerivedEntityType.cs", @"// + "PrincipalDerivedEntityType.cs", +""" +// using System; using System.Data; using System.Reflection; @@ -2710,10 +2742,10 @@ internal partial class PrincipalDerivedEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+PrincipalDerived>"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+PrincipalDerived>", typeof(CSharpRuntimeModelCodeGeneratorTest.PrincipalDerived>), baseEntityType, - discriminatorValue: ""PrincipalDerived>""); + discriminatorValue: "PrincipalDerived>"); return runtimeEntityType; } @@ -2722,50 +2754,50 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { var insertSproc = new RuntimeStoredProcedure( runtimeEntityType, - ""Derived_Insert"", - ""TPC"", + "Derived_Insert", + "TPC", false); var principalBaseId = insertSproc.AddParameter( - ""PrincipalBaseId"", ParameterDirection.Input, false, ""PrincipalBaseId"", false); + "PrincipalBaseId", ParameterDirection.Input, false, "PrincipalBaseId", false); var principalDerivedId = insertSproc.AddParameter( - ""PrincipalDerivedId"", ParameterDirection.Input, false, ""PrincipalDerivedId"", false); + "PrincipalDerivedId", ParameterDirection.Input, false, "PrincipalDerivedId", false); var derivedId = insertSproc.AddResultColumn( - ""DerivedId"", false, ""Id""); - derivedId.AddAnnotation(""foo"", ""bar3""); - runtimeEntityType.AddAnnotation(""Relational:InsertStoredProcedure"", insertSproc); + "DerivedId", false, "Id"); + derivedId.AddAnnotation("foo", "bar3"); + runtimeEntityType.AddAnnotation("Relational:InsertStoredProcedure", insertSproc); var deleteSproc = new RuntimeStoredProcedure( runtimeEntityType, - ""Derived_Delete"", - ""TPC"", + "Derived_Delete", + "TPC", false); var id = deleteSproc.AddParameter( - ""Id_Original"", ParameterDirection.Input, false, ""Id"", true); - runtimeEntityType.AddAnnotation(""Relational:DeleteStoredProcedure"", deleteSproc); + "Id_Original", ParameterDirection.Input, false, "Id", true); + runtimeEntityType.AddAnnotation("Relational:DeleteStoredProcedure", deleteSproc); var updateSproc = new RuntimeStoredProcedure( runtimeEntityType, - ""Derived_Update"", - ""Derived"", + "Derived_Update", + "Derived", false); var principalBaseId0 = updateSproc.AddParameter( - ""PrincipalBaseId"", ParameterDirection.Input, false, ""PrincipalBaseId"", false); + "PrincipalBaseId", ParameterDirection.Input, false, "PrincipalBaseId", false); var principalDerivedId0 = updateSproc.AddParameter( - ""PrincipalDerivedId"", ParameterDirection.Input, false, ""PrincipalDerivedId"", false); + "PrincipalDerivedId", ParameterDirection.Input, false, "PrincipalDerivedId", false); var id0 = updateSproc.AddParameter( - ""Id_Original"", ParameterDirection.Input, false, ""Id"", true); - runtimeEntityType.AddAnnotation(""Relational:UpdateStoredProcedure"", updateSproc); + "Id_Original", ParameterDirection.Input, false, "Id", true); + runtimeEntityType.AddAnnotation("Relational:UpdateStoredProcedure", updateSproc); - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", null); - runtimeEntityType.AddAnnotation(""Relational:Schema"", ""TPC""); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", ""PrincipalDerived""); - runtimeEntityType.AddAnnotation(""Relational:ViewDefinitionSql"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", ""PrincipalDerivedView""); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", ""TPC""); + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", "TPC"); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "PrincipalDerived"); + runtimeEntityType.AddAnnotation("Relational:ViewDefinitionSql", null); + runtimeEntityType.AddAnnotation("Relational:ViewName", "PrincipalDerivedView"); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", "TPC"); Customize(runtimeEntityType); } @@ -2773,7 +2805,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", c)), +""", c)), model => { Assert.Equal("TPC", model.GetDefaultSchema()); @@ -3146,7 +3178,8 @@ public void DbFunctions() code, c => AssertFileContents( "DbFunctionContextModel.cs", - @"// +""" +// using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Scaffolding.Internal; @@ -3175,11 +3208,12 @@ static DbFunctionContextModel() partial void Customize(); } } -", +""", c), c => AssertFileContents( "DbFunctionContextModelBuilder.cs", - @"// +""" +// using System; using System.Collections.Generic; using System.Linq; @@ -3206,27 +3240,27 @@ partial void Initialize() var type = this.AddTypeMappingConfiguration( typeof(string), maxLength: 256); - type.AddAnnotation(""Relational:IsFixedLength"", true); + type.AddAnnotation("Relational:IsFixedLength", true); var functions = new SortedDictionary(); var getBlobs = new RuntimeDbFunction( - ""GetBlobs()"", + "GetBlobs()", this, typeof(IQueryable), - ""GetBlobs"", - schema: ""dbo""); + "GetBlobs", + schema: "dbo"); - functions[""GetBlobs()""] = getBlobs; + functions["GetBlobs()"] = getBlobs; var getCount = new RuntimeDbFunction( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.GetCount(System.Guid?,string)"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.GetCount(System.Guid?,string)", this, typeof(int), - ""CustomerOrderCount"", - schema: ""dbf"", - storeType: ""int"", + "CustomerOrderCount", + schema: "dbf", + storeType: "int", methodInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DbFunctionContext).GetMethod( - ""GetCount"", + "GetCount", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly, null, new Type[] { typeof(Guid?), typeof(string) }, @@ -3234,64 +3268,64 @@ partial void Initialize() scalar: true); var id = getCount.AddParameter( - ""id"", + "id", typeof(Guid?), true, - ""uniqueidentifier""); - id.AddAnnotation(""MyAnnotation"", new[] { 1L }); + "uniqueidentifier"); + id.AddAnnotation("MyAnnotation", new[] { 1L }); var condition = getCount.AddParameter( - ""condition"", + "condition", typeof(string), false, - ""nchar(256)""); + "nchar(256)"); - functions[""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.GetCount(System.Guid?,string)""] = getCount; + functions["Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.GetCount(System.Guid?,string)"] = getCount; var getData = new RuntimeDbFunction( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.GetData()"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.GetData()", this, typeof(IQueryable), - ""GetAllData"", - schema: ""dbo"", + "GetAllData", + schema: "dbo", methodInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DbFunctionContext).GetMethod( - ""GetData"", + "GetData", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly, null, new Type[] { }, null)); - functions[""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.GetData()""] = getData; + functions["Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.GetData()"] = getData; var getData0 = new RuntimeDbFunction( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.GetData(int)"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.GetData(int)", this, typeof(IQueryable), - ""GetData"", - schema: ""dbo"", + "GetData", + schema: "dbo", methodInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DbFunctionContext).GetMethod( - ""GetData"", + "GetData", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly, null, new Type[] { typeof(int) }, null)); var id0 = getData0.AddParameter( - ""id"", + "id", typeof(int), false, - ""int""); + "int"); - functions[""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.GetData(int)""] = getData0; + functions["Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.GetData(int)"] = getData0; var isDateStatic = new RuntimeDbFunction( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.IsDateStatic(string)"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.IsDateStatic(string)", this, typeof(bool), - ""IsDate"", - storeType: ""bit"", + "IsDate", + storeType: "bit", methodInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.DbFunctionContext).GetMethod( - ""IsDateStatic"", + "IsDateStatic", BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly, null, new Type[] { typeof(string) }, @@ -3301,25 +3335,26 @@ partial void Initialize() builtIn: true); var date = isDateStatic.AddParameter( - ""date"", + "date", typeof(string), false, - ""nchar(256)""); + "nchar(256)"); - isDateStatic.AddAnnotation(""MyGuid"", new Guid(""00000000-0000-0000-0000-000000000000"")); - functions[""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.IsDateStatic(string)""] = isDateStatic; + isDateStatic.AddAnnotation("MyGuid", new Guid("00000000-0000-0000-0000-000000000000")); + functions["Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.IsDateStatic(string)"] = isDateStatic; - AddAnnotation(""Relational:DbFunctions"", functions); - AddAnnotation(""Relational:MaxIdentifierLength"", 128); - AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn); + AddAnnotation("Relational:DbFunctions", functions); + AddAnnotation("Relational:MaxIdentifierLength", 128); + AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); } } } -", +""", c), c => AssertFileContents( "DataEntityType.cs", - @"// +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore.Metadata; @@ -3335,29 +3370,29 @@ internal partial class DataEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+Data"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+Data", typeof(CSharpRuntimeModelCodeGeneratorTest.Data), baseEntityType); var blob = runtimeEntityType.AddProperty( - ""Blob"", + "Blob", typeof(byte[]), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetProperty(""Blob"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetProperty("Blob", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); - blob.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + blob.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); return runtimeEntityType; } public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.GetData()""); - runtimeEntityType.AddAnnotation(""Relational:Schema"", null); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", null); + runtimeEntityType.AddAnnotation("Relational:FunctionName", "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+DbFunctionContext.GetData()"); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", null); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); Customize(runtimeEntityType); } @@ -3365,11 +3400,12 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", +""", c), c => AssertFileContents( "ObjectEntityType.cs", - @"// +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore.Metadata; @@ -3384,7 +3420,7 @@ internal partial class ObjectEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""object"", + "object", typeof(object), baseEntityType); @@ -3393,12 +3429,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", ""GetBlobs()""); - runtimeEntityType.AddAnnotation(""Relational:Schema"", null); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", null); + runtimeEntityType.AddAnnotation("Relational:FunctionName", "GetBlobs()"); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", null); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); Customize(runtimeEntityType); } @@ -3406,7 +3442,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", +""", c)), model => { @@ -3636,7 +3672,8 @@ public void Sequences() code, c => AssertFileContents( "SequencesContextModel.cs", - @"// +""" +// using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Scaffolding.Internal; @@ -3665,11 +3702,12 @@ static SequencesContextModel() partial void Customize(); } } -", +""", c), c => AssertFileContents( "SequencesContextModelBuilder.cs", - @"// +""" +// using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -3690,16 +3728,16 @@ partial void Initialize() var sequences = new SortedDictionary<(string, string), ISequence>(); var hL = new RuntimeSequence( - ""HL"", + "HL", this, typeof(long), - schema: ""S"", + schema: "S", incrementBy: 10); - sequences[(""HL"", ""S"")] = hL; + sequences[("HL", "S")] = hL; var @long = new RuntimeSequence( - ""Long"", + "Long", this, typeof(long), startValue: -4L, @@ -3708,19 +3746,20 @@ partial void Initialize() minValue: -2L, maxValue: 2L); - sequences[(""Long"", null)] = @long; + sequences[("Long", null)] = @long; - AddAnnotation(""Relational:Sequences"", sequences); - AddAnnotation(""Relational:MaxIdentifierLength"", 128); - AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn); + AddAnnotation("Relational:Sequences", sequences); + AddAnnotation("Relational:MaxIdentifierLength", 128); + AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); } } } -", +""", c), c => AssertFileContents( "DataEntityType.cs", - @"// +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore.Metadata; @@ -3736,26 +3775,26 @@ internal partial class DataEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+Data"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+Data", typeof(CSharpRuntimeModelCodeGeneratorTest.Data), baseEntityType); var id = runtimeEntityType.AddProperty( - ""Id"", + "Id", typeof(int), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); - id.AddAnnotation(""SqlServer:HiLoSequenceName"", ""HL""); - id.AddAnnotation(""SqlServer:HiLoSequenceSchema"", ""S""); - id.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.SequenceHiLo); + id.AddAnnotation("SqlServer:HiLoSequenceName", "HL"); + id.AddAnnotation("SqlServer:HiLoSequenceSchema", "S"); + id.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); var blob = runtimeEntityType.AddProperty( - ""Blob"", + "Blob", typeof(byte[]), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetProperty(""Blob"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetProperty("Blob", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); - blob.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + blob.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var key = runtimeEntityType.AddKey( new[] { id }); @@ -3766,12 +3805,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", null); - runtimeEntityType.AddAnnotation(""Relational:Schema"", null); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", ""Data""); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", null); + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Data"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); Customize(runtimeEntityType); } @@ -3779,7 +3818,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", +""", c)), model => { @@ -3842,7 +3881,8 @@ public void Key_sequences() code, c => AssertFileContents( "KeySequencesContextModel.cs", - @"// +""" +// using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Scaffolding.Internal; @@ -3871,11 +3911,12 @@ static KeySequencesContextModel() partial void Customize(); } } -", +""", c), c => AssertFileContents( "KeySequencesContextModelBuilder.cs", - @"// +""" +// using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -3896,24 +3937,25 @@ partial void Initialize() var sequences = new SortedDictionary<(string, string), ISequence>(); var keySeq = new RuntimeSequence( - ""KeySeq"", + "KeySeq", this, typeof(long), - schema: ""KeySeqSchema""); + schema: "KeySeqSchema"); - sequences[(""KeySeq"", ""KeySeqSchema"")] = keySeq; + sequences[("KeySeq", "KeySeqSchema")] = keySeq; - AddAnnotation(""Relational:Sequences"", sequences); - AddAnnotation(""Relational:MaxIdentifierLength"", 128); - AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn); + AddAnnotation("Relational:Sequences", sequences); + AddAnnotation("Relational:MaxIdentifierLength", 128); + AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); } } } -", +""", c), c => AssertFileContents( "DataEntityType.cs", - @"// +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore.Metadata; @@ -3929,27 +3971,27 @@ internal partial class DataEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+Data"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+Data", typeof(CSharpRuntimeModelCodeGeneratorTest.Data), baseEntityType); var id = runtimeEntityType.AddProperty( - ""Id"", + "Id", typeof(int), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); - id.AddAnnotation(""Relational:DefaultValueSql"", ""NEXT VALUE FOR [KeySeqSchema].[KeySeq]""); - id.AddAnnotation(""SqlServer:SequenceName"", ""KeySeq""); - id.AddAnnotation(""SqlServer:SequenceSchema"", ""KeySeqSchema""); - id.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.Sequence); + id.AddAnnotation("Relational:DefaultValueSql", "NEXT VALUE FOR [KeySeqSchema].[KeySeq]"); + id.AddAnnotation("SqlServer:SequenceName", "KeySeq"); + id.AddAnnotation("SqlServer:SequenceSchema", "KeySeqSchema"); + id.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.Sequence); var blob = runtimeEntityType.AddProperty( - ""Blob"", + "Blob", typeof(byte[]), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetProperty(""Blob"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetProperty("Blob", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); - blob.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + blob.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var key = runtimeEntityType.AddKey( new[] { id }); @@ -3960,12 +4002,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", null); - runtimeEntityType.AddAnnotation(""Relational:Schema"", null); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", ""Data""); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", null); + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Data"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); Customize(runtimeEntityType); } @@ -3973,7 +4015,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", +""", c)), model => { @@ -4019,7 +4061,8 @@ public void CheckConstraints() code, c => AssertFileContents( "ConstraintsContextModel.cs", - @"// +""" +// using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Scaffolding.Internal; @@ -4048,11 +4091,12 @@ static ConstraintsContextModel() partial void Customize(); } } -", +""", c), c => AssertFileContents( "ConstraintsContextModelBuilder.cs", - @"// +""" +// using System; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -4070,16 +4114,17 @@ partial void Initialize() DataEntityType.CreateAnnotations(data); - AddAnnotation(""Relational:MaxIdentifierLength"", 128); - AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn); + AddAnnotation("Relational:MaxIdentifierLength", 128); + AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); } } } -", +""", c), c => AssertFileContents( "DataEntityType.cs", - @"// +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore.Metadata; @@ -4095,24 +4140,24 @@ internal partial class DataEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+Data"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+Data", typeof(CSharpRuntimeModelCodeGeneratorTest.Data), baseEntityType); var id = runtimeEntityType.AddProperty( - ""Id"", + "Id", typeof(int), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); - id.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn); + id.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); var blob = runtimeEntityType.AddProperty( - ""Blob"", + "Blob", typeof(byte[]), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetProperty(""Blob"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetProperty("Blob", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); - blob.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + blob.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var key = runtimeEntityType.AddKey( new[] { id }); @@ -4123,12 +4168,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", null); - runtimeEntityType.AddAnnotation(""Relational:Schema"", null); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", ""Data""); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", null); + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Data"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); Customize(runtimeEntityType); } @@ -4136,7 +4181,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", +""", c)), model => { @@ -4174,7 +4219,8 @@ public void Triggers() code, c => AssertFileContents( "TriggersContextModel.cs", - @"// +""" +// using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Scaffolding.Internal; @@ -4203,11 +4249,12 @@ static TriggersContextModel() partial void Customize(); } } -", +""", c), c => AssertFileContents( "TriggersContextModelBuilder.cs", - @"// +""" +// using System; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -4225,16 +4272,17 @@ partial void Initialize() DataEntityType.CreateAnnotations(data); - AddAnnotation(""Relational:MaxIdentifierLength"", 128); - AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn); + AddAnnotation("Relational:MaxIdentifierLength", 128); + AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); } } } -", +""", c), c => AssertFileContents( "DataEntityType.cs", - @"// +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore.Metadata; @@ -4250,46 +4298,46 @@ internal partial class DataEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+Data"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+Data", typeof(CSharpRuntimeModelCodeGeneratorTest.Data), baseEntityType); var id = runtimeEntityType.AddProperty( - ""Id"", + "Id", typeof(int), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); - id.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn); + id.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); var blob = runtimeEntityType.AddProperty( - ""Blob"", + "Blob", typeof(byte[]), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetProperty(""Blob"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetProperty("Blob", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); - blob.AddAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.None); + blob.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); var key = runtimeEntityType.AddKey( new[] { id }); runtimeEntityType.SetPrimaryKey(key); var trigger1 = runtimeEntityType.AddTrigger( - ""Trigger1""); + "Trigger1"); var trigger2 = runtimeEntityType.AddTrigger( - ""Trigger2""); + "Trigger2"); return runtimeEntityType; } public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", null); - runtimeEntityType.AddAnnotation(""Relational:Schema"", null); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", ""Data""); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", null); + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Data"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); Customize(runtimeEntityType); } @@ -4297,7 +4345,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", +""", c)), model => { @@ -4339,7 +4387,8 @@ public void Sqlite() code, c => AssertFileContents( "SqliteContextModel.cs", - @"// +""" +// using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Scaffolding.Internal; @@ -4367,11 +4416,12 @@ static SqliteContextModel() partial void Customize(); } } -", +""", c), c => AssertFileContents( "SqliteContextModelBuilder.cs", - @"// +""" +// using Microsoft.EntityFrameworkCore.Infrastructure; #pragma warning disable 219, 612, 618 @@ -4390,11 +4440,12 @@ partial void Initialize() } } } -", +""", c), c => AssertFileContents( "DataEntityType.cs", - @"// +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore.Scaffolding.Internal; @@ -4410,25 +4461,25 @@ internal partial class DataEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+Data"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+Data", typeof(CSharpRuntimeModelCodeGeneratorTest.Data), baseEntityType); var id = runtimeEntityType.AddProperty( - ""Id"", + "Id", typeof(int), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); var blob = runtimeEntityType.AddProperty( - ""Blob"", + "Blob", typeof(byte[]), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetProperty(""Blob"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetProperty("Blob", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var point = runtimeEntityType.AddProperty( - ""Point"", + "Point", typeof(Point), nullable: true); @@ -4441,12 +4492,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { - runtimeEntityType.AddAnnotation(""Relational:FunctionName"", null); - runtimeEntityType.AddAnnotation(""Relational:Schema"", null); - runtimeEntityType.AddAnnotation(""Relational:SqlQuery"", null); - runtimeEntityType.AddAnnotation(""Relational:TableName"", ""Data""); - runtimeEntityType.AddAnnotation(""Relational:ViewName"", null); - runtimeEntityType.AddAnnotation(""Relational:ViewSchema"", null); + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Data"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); Customize(runtimeEntityType); } @@ -4454,7 +4505,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", +""", c)), model => { @@ -4516,7 +4567,8 @@ public void Cosmos() code, c => AssertFileContents( "CosmosContextModel.cs", - @"// +""" +// using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Scaffolding.Internal; @@ -4545,11 +4597,12 @@ static CosmosContextModel() partial void Customize(); } } -", +""", c), c => AssertFileContents( "CosmosContextModelBuilder.cs", - @"// +""" +// using System; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -4567,15 +4620,16 @@ partial void Initialize() DataEntityType.CreateAnnotations(data); - AddAnnotation(""Cosmos:ContainerName"", ""Default""); + AddAnnotation("Cosmos:ContainerName", "Default"); } } } -", +""", c), c => AssertFileContents( "DataEntityType.cs", - @"// +""" +// using System; using System.Reflection; using Microsoft.EntityFrameworkCore.Cosmos.ValueGeneration; @@ -4593,47 +4647,47 @@ internal partial class DataEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - ""Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+Data"", + "Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGeneratorTest+Data", typeof(CSharpRuntimeModelCodeGeneratorTest.Data), baseEntityType); var id = runtimeEntityType.AddProperty( - ""Id"", + "Id", typeof(int), afterSaveBehavior: PropertySaveBehavior.Throw); var partitionId = runtimeEntityType.AddProperty( - ""PartitionId"", + "PartitionId", typeof(long?), afterSaveBehavior: PropertySaveBehavior.Throw, providerPropertyType: typeof(string)); var blob = runtimeEntityType.AddProperty( - ""Blob"", + "Blob", typeof(byte[]), - propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetProperty(""Blob"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetField(""k__BackingField"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + propertyInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetProperty("Blob", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CSharpRuntimeModelCodeGeneratorTest.Data).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); - blob.AddAnnotation(""Cosmos:PropertyName"", ""JsonBlob""); + blob.AddAnnotation("Cosmos:PropertyName", "JsonBlob"); var __id = runtimeEntityType.AddProperty( - ""__id"", + "__id", typeof(string), afterSaveBehavior: PropertySaveBehavior.Throw, valueGeneratorFactory: new IdValueGeneratorFactory().Create); - __id.AddAnnotation(""Cosmos:PropertyName"", ""id""); + __id.AddAnnotation("Cosmos:PropertyName", "id"); var __jObject = runtimeEntityType.AddProperty( - ""__jObject"", + "__jObject", typeof(JObject), nullable: true, valueGenerated: ValueGenerated.OnAddOrUpdate, beforeSaveBehavior: PropertySaveBehavior.Ignore, afterSaveBehavior: PropertySaveBehavior.Ignore); - __jObject.AddAnnotation(""Cosmos:PropertyName"", """"); + __jObject.AddAnnotation("Cosmos:PropertyName", ""); var _etag = runtimeEntityType.AddProperty( - ""_etag"", + "_etag", typeof(string), nullable: true, concurrencyToken: true, @@ -4653,9 +4707,9 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { - runtimeEntityType.AddAnnotation(""Cosmos:ContainerName"", ""DataContainer""); - runtimeEntityType.AddAnnotation(""Cosmos:ETagName"", ""_etag""); - runtimeEntityType.AddAnnotation(""Cosmos:PartitionKeyName"", ""PartitionId""); + runtimeEntityType.AddAnnotation("Cosmos:ContainerName", "DataContainer"); + runtimeEntityType.AddAnnotation("Cosmos:ETagName", "_etag"); + runtimeEntityType.AddAnnotation("Cosmos:PartitionKeyName", "PartitionId"); Customize(runtimeEntityType); } @@ -4663,7 +4717,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) static partial void Customize(RuntimeEntityType runtimeEntityType); } } -", +""", c)), model => { @@ -4930,7 +4984,7 @@ protected static void AssertFileContents( ScaffoldedFile file) { Assert.Equal(expectedPath, file.Path); - Assert.Equal(expectedCode, file.Code, ignoreLineEndingDifferences: true); + Assert.Equal(expectedCode, file.Code.TrimEnd(), ignoreLineEndingDifferences: true); } } diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/ModelCodeGeneratorTestBase.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/ModelCodeGeneratorTestBase.cs index 2bb0d3a50d1..529de90dc7d 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/ModelCodeGeneratorTestBase.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/ModelCodeGeneratorTestBase.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.InteropServices; +using System.Text.RegularExpressions; using Microsoft.EntityFrameworkCore.Design.Internal; namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal; @@ -106,5 +107,19 @@ protected virtual void AddScaffoldingServices(IServiceCollection services) protected static void AssertFileContents( string expectedCode, ScaffoldedFile file) - => Assert.Equal(expectedCode, file.Code, ignoreLineEndingDifferences: true); + => Assert.Equal(expectedCode, file.Code.TrimEnd(), ignoreLineEndingDifferences: true); + + protected static void AssertContains( + string expected, + string actual) + { + // Normalize line endings to Environment.Newline + expected = expected + .Replace("\r\n", "\n") + .Replace("\n\r", "\n") + .Replace("\r", "\n") + .Replace("\n", Environment.NewLine); + + Assert.Contains(expected, actual); + } } diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/TextTemplatingModelGeneratorTest.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/TextTemplatingModelGeneratorTest.cs index 5f751554751..f9a76334c97 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/TextTemplatingModelGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/TextTemplatingModelGeneratorTest.cs @@ -200,24 +200,30 @@ public void GenerateModel_sets_session_variables() Directory.CreateDirectory(Path.GetDirectoryName(contextTemplate)); File.WriteAllText( contextTemplate, - @"Model not null: <#= Session[""Model""] != null #> -Options not null: <#= Session[""Options""] != null #> -NamespaceHint: <#= Session[""NamespaceHint""] #> -ProjectDefaultNamespace: <#= Session[""ProjectDefaultNamespace""] #>"); +""" +Model not null: <#= Session["Model"] != null #> +Options not null: <#= Session["Options"] != null #> +NamespaceHint: <#= Session["NamespaceHint"] #> +ProjectDefaultNamespace: <#= Session["ProjectDefaultNamespace"] #> +"""); File.WriteAllText( Path.Combine(projectDir, "CodeTemplates", "EFCore", "EntityType.t4"), - @"EntityType not null: <#= Session[""EntityType""] != null #> -Options not null: <#= Session[""Options""] != null #> -NamespaceHint: <#= Session[""NamespaceHint""] #> -ProjectDefaultNamespace: <#= Session[""ProjectDefaultNamespace""] #>"); +""" +EntityType not null: <#= Session["EntityType"] != null #> +Options not null: <#= Session["Options"] != null #> +NamespaceHint: <#= Session["NamespaceHint"] #> +ProjectDefaultNamespace: <#= Session["ProjectDefaultNamespace"] #> +"""); File.WriteAllText( Path.Combine(projectDir, "CodeTemplates", "EFCore", "EntityTypeConfiguration.t4"), - @"EntityType not null: <#= Session[""EntityType""] != null #> -Options not null: <#= Session[""Options""] != null #> -NamespaceHint: <#= Session[""NamespaceHint""] #> -ProjectDefaultNamespace: <#= Session[""ProjectDefaultNamespace""] #>"); +""" +EntityType not null: <#= Session["EntityType"] != null #> +Options not null: <#= Session["Options"] != null #> +NamespaceHint: <#= Session["NamespaceHint"] #> +ProjectDefaultNamespace: <#= Session["ProjectDefaultNamespace"] #> +"""); var generator = CreateGenerator(); var model = new ModelBuilder() @@ -237,28 +243,34 @@ public void GenerateModel_sets_session_variables() }); Assert.Equal( - @"Model not null: True +""" +Model not null: True Options not null: True NamespaceHint: ContextNamespace -ProjectDefaultNamespace: RootNamespace", +ProjectDefaultNamespace: RootNamespace +""", result.ContextFile.Code); Assert.Equal(2, result.AdditionalFiles.Count); var entityType = Assert.Single(result.AdditionalFiles, f => f.Path == "Entity1.cs"); Assert.Equal( - @"EntityType not null: True +""" +EntityType not null: True Options not null: True NamespaceHint: ModelNamespace -ProjectDefaultNamespace: RootNamespace", +ProjectDefaultNamespace: RootNamespace +""", entityType.Code); var entityTypeConfiguration = Assert.Single(result.AdditionalFiles, f => f.Path == "Entity1Configuration.cs"); Assert.Equal( - @"EntityType not null: True +""" +EntityType not null: True Options not null: True NamespaceHint: ContextNamespace -ProjectDefaultNamespace: RootNamespace", +ProjectDefaultNamespace: RootNamespace +""", entityTypeConfiguration.Code); } @@ -315,13 +327,17 @@ public void GenerateModel_uses_output_extension() File.WriteAllText( Path.Combine(projectDir, "CodeTemplates", "EFCore", "EntityType.t4"), - @"<#@ output extension="".fs"" #> -My entity type template"); +""" +<#@ output extension=".fs" #> +My entity type template +"""); File.WriteAllText( Path.Combine(projectDir, "CodeTemplates", "EFCore", "EntityTypeConfiguration.t4"), - @"<#@ output extension="".py"" #> -My entity type configuration template"); +""" +<#@ output extension=".py" #> +My entity type configuration template +"""); var generator = CreateGenerator(); var model = new ModelBuilder() @@ -431,9 +447,11 @@ public void GenerateModel_reports_warnings() var entityTypeTemplate = Path.Combine(projectDir, "CodeTemplates", "EFCore", "EntityType.t4"); File.WriteAllText( entityTypeTemplate, - @"<#@ assembly name=""Microsoft.EntityFrameworkCore"" #> -<#@ parameter name=""EntityType"" type=""Microsoft.EntityFrameworkCore.Metadata.IEntityType"" #> -<# Warning(""Warning about "" + EntityType.Name); #>"); +""" +<#@ assembly name="Microsoft.EntityFrameworkCore" #> +<#@ parameter name="EntityType" type="Microsoft.EntityFrameworkCore.Metadata.IEntityType" #> +<# Warning("Warning about " + EntityType.Name); #> +"""); var reporter = new TestOperationReporter(); var generator = CreateGenerator(reporter);