diff --git a/.github/workflows/.net-build.yml b/.github/workflows/.net-build.yml index be8b071..d74c368 100644 --- a/.github/workflows/.net-build.yml +++ b/.github/workflows/.net-build.yml @@ -24,7 +24,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0.100 + dotnet-version: 10.0.100 - name: Tests run: dotnet test EntityFrameworkCore.SqlServer.SimpleBulks.Tests/EntityFrameworkCore.SqlServer.SimpleBulks.Tests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura diff --git a/.github/workflows/.net-test-connection-extensions-discriminator-enabled.yml b/.github/workflows/.net-test-connection-extensions-discriminator-enabled.yml index d41639c..35fd057 100644 --- a/.github/workflows/.net-test-connection-extensions-discriminator-enabled.yml +++ b/.github/workflows/.net-test-connection-extensions-discriminator-enabled.yml @@ -24,7 +24,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0.100 + dotnet-version: 10.0.100 - name: Tests run: dotnet test EntityFrameworkCore.SqlServer.SimpleBulks.Tests/EntityFrameworkCore.SqlServer.SimpleBulks.Tests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura diff --git a/.github/workflows/.net-test-connection-extensions.yml b/.github/workflows/.net-test-connection-extensions.yml index b963fba..6040e92 100644 --- a/.github/workflows/.net-test-connection-extensions.yml +++ b/.github/workflows/.net-test-connection-extensions.yml @@ -24,7 +24,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0.100 + dotnet-version: 10.0.100 - name: Tests run: dotnet test EntityFrameworkCore.SqlServer.SimpleBulks.Tests/EntityFrameworkCore.SqlServer.SimpleBulks.Tests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura diff --git a/.github/workflows/.net-test-dbcontext-extensions-discriminator-enabled.yml b/.github/workflows/.net-test-dbcontext-extensions-discriminator-enabled.yml index 5e9a204..0bf56e5 100644 --- a/.github/workflows/.net-test-dbcontext-extensions-discriminator-enabled.yml +++ b/.github/workflows/.net-test-dbcontext-extensions-discriminator-enabled.yml @@ -24,7 +24,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0.100 + dotnet-version: 10.0.100 - name: Tests run: dotnet test EntityFrameworkCore.SqlServer.SimpleBulks.Tests/EntityFrameworkCore.SqlServer.SimpleBulks.Tests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura diff --git a/.github/workflows/.net-test-dbcontext-extensions.yml b/.github/workflows/.net-test-dbcontext-extensions.yml index 83bb26e..e1f79d6 100644 --- a/.github/workflows/.net-test-dbcontext-extensions.yml +++ b/.github/workflows/.net-test-dbcontext-extensions.yml @@ -24,7 +24,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0.100 + dotnet-version: 10.0.100 - name: Tests run: dotnet test EntityFrameworkCore.SqlServer.SimpleBulks.Tests/EntityFrameworkCore.SqlServer.SimpleBulks.Tests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura diff --git a/src/DbContextExtensionsExamples/DemoDbContext.cs b/src/DbContextExtensionsExamples/DemoDbContext.cs index e704555..3bd8a66 100644 --- a/src/DbContextExtensionsExamples/DemoDbContext.cs +++ b/src/DbContextExtensionsExamples/DemoDbContext.cs @@ -2,8 +2,6 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; using System; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; namespace DbContextExtensionsExamples; @@ -17,12 +15,22 @@ public class DemoDbContext : DbContext public DbSet ConfigurationEntries { get; set; } - public DbSet Orders { get; set; } - public DbSet Blogs { get; set; } public DbSet RssBlogs { get; set; } + public DbSet ComplexTypeOrders { get; set; } + + public DbSet OwnedTypeOrders { get; set; } + + public DbSet ComplexOwnedTypeOrders { get; set; } + + public DbSet JsonComplexTypeOrders { get; set; } + + public DbSet JsonOwnedTypeOrders { get; set; } + + public DbSet JsonComplexOwnedTypeOrders { get; set; } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(_connectionString); @@ -42,35 +50,50 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity().Property(x => x.Id).HasColumnName("Id1"); modelBuilder.Entity().Property(x => x.SeasonAsString).HasConversion(v => v.ToString(), v => (Season)Enum.Parse(typeof(Season), v)); + modelBuilder.Entity().ComplexProperty(x => x.ShippingAddress, x => + { + x.ToJson(); + //x.ToJson("xxx").HasColumnType("json"); + x.ComplexProperty(y => y.Location, y => + { + y.HasJsonPropertyName("xxx"); + }); + }); + + modelBuilder.Entity().OwnsOne(x => x.ShippingAddress, x => + { + x.ToJson(); + //x.ToJson("xxx").HasColumnType("json"); + x.OwnsOne(y => y.Location, y => + { + y.HasJsonPropertyName("xxx"); + }); + }); + + modelBuilder.Entity().ComplexProperty(x => x.ComplexShippingAddress, x => + { + x.ToJson(); + //x.ToJson("xxx").HasColumnType("json"); + x.ComplexProperty(y => y.Location, y => + { + y.HasJsonPropertyName("xxx"); + }); + }); + + modelBuilder.Entity().OwnsOne(x => x.OwnedShippingAddress, x => + { + x.ToJson(); + //x.ToJson("xxx").HasColumnType("json"); + x.OwnsOne(y => y.Location, y => + { + y.HasJsonPropertyName("xxx"); + }); + }); + base.OnModelCreating(modelBuilder); } } -public class Order -{ - public int Id { get; set; } - - [Required] - public Address ShippingAddress { get; set; } -} - -[ComplexType] -public class Address -{ - public string Street { get; set; } - - [Required] - public Location Location { get; set; } -} - -[ComplexType] -public class Location -{ - public double Lat { get; set; } - - public double Lng { get; set; } -} - public class Blog { public int BlogId { get; set; } diff --git a/src/DbContextExtensionsExamples/Entities/ComplexOwnedTypeOrder.cs b/src/DbContextExtensionsExamples/Entities/ComplexOwnedTypeOrder.cs new file mode 100644 index 0000000..a31a1c9 --- /dev/null +++ b/src/DbContextExtensionsExamples/Entities/ComplexOwnedTypeOrder.cs @@ -0,0 +1,25 @@ +using System.ComponentModel.DataAnnotations; + +namespace DbContextExtensionsExamples.Entities; + +public class ComplexOwnedTypeOrder +{ + public int Id { get; set; } + + [Required] + public ComplexTypeAddress ComplexShippingAddress { get; set; } + + [Required] + public OwnedTypeAddress OwnedShippingAddress { get; set; } +} + +public class JsonComplexOwnedTypeOrder +{ + public int Id { get; set; } + + [Required] + public ComplexTypeAddress ComplexShippingAddress { get; set; } + + [Required] + public OwnedTypeAddress OwnedShippingAddress { get; set; } +} \ No newline at end of file diff --git a/src/DbContextExtensionsExamples/Entities/ComplexTypeOrder.cs b/src/DbContextExtensionsExamples/Entities/ComplexTypeOrder.cs new file mode 100644 index 0000000..a4a0ac4 --- /dev/null +++ b/src/DbContextExtensionsExamples/Entities/ComplexTypeOrder.cs @@ -0,0 +1,36 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace DbContextExtensionsExamples.Entities; + +public class ComplexTypeOrder +{ + public int Id { get; set; } + + [Required] + public ComplexTypeAddress ShippingAddress { get; set; } +} + +[ComplexType] +public class ComplexTypeAddress +{ + public string Street { get; set; } + + public ComplexTypeLocation Location { get; set; } +} + +[ComplexType] +public class ComplexTypeLocation +{ + public double Lat { get; set; } + + public double Lng { get; set; } +} + +public class JsonComplexTypeOrder +{ + public int Id { get; set; } + + [Required] + public ComplexTypeAddress ShippingAddress { get; set; } +} \ No newline at end of file diff --git a/src/DbContextExtensionsExamples/Entities/OwnedTypeOrder.cs b/src/DbContextExtensionsExamples/Entities/OwnedTypeOrder.cs new file mode 100644 index 0000000..c49cf27 --- /dev/null +++ b/src/DbContextExtensionsExamples/Entities/OwnedTypeOrder.cs @@ -0,0 +1,37 @@ +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; + +namespace DbContextExtensionsExamples.Entities; + +public class OwnedTypeOrder +{ + public int Id { get; set; } + + [Required] + public OwnedTypeAddress ShippingAddress { get; set; } +} + +[Owned] +public class OwnedTypeAddress +{ + public string Street { get; set; } + + [Required] + public OwnedTypeLocation Location { get; set; } +} + +[Owned] +public class OwnedTypeLocation +{ + public double Lat { get; set; } + + public double Lng { get; set; } +} + +public class JsonOwnedTypeOrder +{ + public int Id { get; set; } + + [Required] + public OwnedTypeAddress ShippingAddress { get; set; } +} \ No newline at end of file diff --git a/src/DbContextExtensionsExamples/Migrations/20251024140719_Init.Designer.cs b/src/DbContextExtensionsExamples/Migrations/20251024140719_Init.Designer.cs deleted file mode 100644 index 6090c2b..0000000 --- a/src/DbContextExtensionsExamples/Migrations/20251024140719_Init.Designer.cs +++ /dev/null @@ -1,117 +0,0 @@ -// -using System; -using DbContextExtensionsExamples; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace DbContextExtensionsExamples.Migrations -{ - [DbContext(typeof(DemoDbContext))] - [Migration("20251024140719_Init")] - partial class Init - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("DbContextExtensionsExamples.Entities.CompositeKeyRow", b => - { - b.Property("Id1") - .HasColumnType("int"); - - b.Property("Id2") - .HasColumnType("int"); - - b.Property("Column1") - .HasColumnType("int"); - - b.Property("Column2") - .HasColumnType("nvarchar(max)"); - - b.Property("Column3") - .HasColumnType("datetime2"); - - b.HasKey("Id1", "Id2"); - - b.ToTable("CompositeKeyRows"); - }); - - modelBuilder.Entity("DbContextExtensionsExamples.Entities.ConfigurationEntry", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasColumnName("Id1") - .HasDefaultValueSql("newsequentialid()"); - - b.Property("CreatedDateTime") - .HasColumnType("datetimeoffset"); - - b.Property("Description") - .HasColumnType("nvarchar(max)"); - - b.Property("IsSensitive") - .HasColumnType("bit"); - - b.Property("Key") - .HasColumnType("nvarchar(max)") - .HasColumnName("Key1"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .ValueGeneratedOnAddOrUpdate() - .HasColumnType("rowversion"); - - b.Property("SeasonAsInt") - .HasColumnType("int"); - - b.Property("SeasonAsString") - .HasColumnType("nvarchar(max)"); - - b.Property("UpdatedDateTime") - .HasColumnType("datetimeoffset"); - - b.Property("Value") - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("ConfigurationEntries"); - }); - - modelBuilder.Entity("DbContextExtensionsExamples.Entities.Row", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Column1") - .HasColumnType("int"); - - b.Property("Column2") - .HasColumnType("nvarchar(max)"); - - b.Property("Column3") - .HasColumnType("datetime2"); - - b.HasKey("Id"); - - b.ToTable("Rows"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/DbContextExtensionsExamples/Migrations/20251024140719_Init.cs b/src/DbContextExtensionsExamples/Migrations/20251024140719_Init.cs deleted file mode 100644 index ed5353f..0000000 --- a/src/DbContextExtensionsExamples/Migrations/20251024140719_Init.cs +++ /dev/null @@ -1,77 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; -using System; - -#nullable disable - -namespace DbContextExtensionsExamples.Migrations; - -/// -public partial class Init : Migration -{ - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "CompositeKeyRows", - columns: table => new - { - Id1 = table.Column(type: "int", nullable: false), - Id2 = table.Column(type: "int", nullable: false), - Column1 = table.Column(type: "int", nullable: false), - Column2 = table.Column(type: "nvarchar(max)", nullable: true), - Column3 = table.Column(type: "datetime2", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_CompositeKeyRows", x => new { x.Id1, x.Id2 }); - }); - - migrationBuilder.CreateTable( - name: "ConfigurationEntries", - columns: table => new - { - Id1 = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "newsequentialid()"), - RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: true), - CreatedDateTime = table.Column(type: "datetimeoffset", nullable: false), - UpdatedDateTime = table.Column(type: "datetimeoffset", nullable: true), - Key1 = table.Column(type: "nvarchar(max)", nullable: true), - Value = table.Column(type: "nvarchar(max)", nullable: true), - Description = table.Column(type: "nvarchar(max)", nullable: true), - IsSensitive = table.Column(type: "bit", nullable: false), - SeasonAsInt = table.Column(type: "int", nullable: true), - SeasonAsString = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_ConfigurationEntries", x => x.Id1); - }); - - migrationBuilder.CreateTable( - name: "Rows", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Column1 = table.Column(type: "int", nullable: false), - Column2 = table.Column(type: "nvarchar(max)", nullable: true), - Column3 = table.Column(type: "datetime2", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Rows", x => x.Id); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "CompositeKeyRows"); - - migrationBuilder.DropTable( - name: "ConfigurationEntries"); - - migrationBuilder.DropTable( - name: "Rows"); - } -} diff --git a/src/DbContextExtensionsExamples/Migrations/20251204104144_ComplexType.Designer.cs b/src/DbContextExtensionsExamples/Migrations/20251204104144_ComplexType.Designer.cs deleted file mode 100644 index ed9de4b..0000000 --- a/src/DbContextExtensionsExamples/Migrations/20251204104144_ComplexType.Designer.cs +++ /dev/null @@ -1,150 +0,0 @@ -// -using System; -using System.Collections.Generic; -using DbContextExtensionsExamples; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace DbContextExtensionsExamples.Migrations -{ - [DbContext(typeof(DemoDbContext))] - [Migration("20251204104144_ComplexType")] - partial class ComplexType - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("DbContextExtensionsExamples.Entities.CompositeKeyRow", b => - { - b.Property("Id1") - .HasColumnType("int"); - - b.Property("Id2") - .HasColumnType("int"); - - b.Property("Column1") - .HasColumnType("int"); - - b.Property("Column2") - .HasColumnType("nvarchar(max)"); - - b.Property("Column3") - .HasColumnType("datetime2"); - - b.HasKey("Id1", "Id2"); - - b.ToTable("CompositeKeyRows"); - }); - - modelBuilder.Entity("DbContextExtensionsExamples.Entities.ConfigurationEntry", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasColumnName("Id1") - .HasDefaultValueSql("newsequentialid()"); - - b.Property("CreatedDateTime") - .HasColumnType("datetimeoffset"); - - b.Property("Description") - .HasColumnType("nvarchar(max)"); - - b.Property("IsSensitive") - .HasColumnType("bit"); - - b.Property("Key") - .HasColumnType("nvarchar(max)") - .HasColumnName("Key1"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .ValueGeneratedOnAddOrUpdate() - .HasColumnType("rowversion"); - - b.Property("SeasonAsInt") - .HasColumnType("int"); - - b.Property("SeasonAsString") - .HasColumnType("nvarchar(max)"); - - b.Property("UpdatedDateTime") - .HasColumnType("datetimeoffset"); - - b.Property("Value") - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("ConfigurationEntries"); - }); - - modelBuilder.Entity("DbContextExtensionsExamples.Entities.Row", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Column1") - .HasColumnType("int"); - - b.Property("Column2") - .HasColumnType("nvarchar(max)"); - - b.Property("Column3") - .HasColumnType("datetime2"); - - b.HasKey("Id"); - - b.ToTable("Rows"); - }); - - modelBuilder.Entity("DbContextExtensionsExamples.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.ComplexProperty>("ShippingAddress", "DbContextExtensionsExamples.Order.ShippingAddress#Address", b1 => - { - b1.IsRequired(); - - b1.Property("Street") - .HasColumnType("nvarchar(max)"); - - b1.ComplexProperty>("Location", "DbContextExtensionsExamples.Order.ShippingAddress#Address.Location#Location", b2 => - { - b2.IsRequired(); - - b2.Property("Lat") - .HasColumnType("float"); - - b2.Property("Lng") - .HasColumnType("float"); - }); - }); - - b.HasKey("Id"); - - b.ToTable("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/DbContextExtensionsExamples/Migrations/20251204104144_ComplexType.cs b/src/DbContextExtensionsExamples/Migrations/20251204104144_ComplexType.cs deleted file mode 100644 index e4e9846..0000000 --- a/src/DbContextExtensionsExamples/Migrations/20251204104144_ComplexType.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace DbContextExtensionsExamples.Migrations -{ - /// - public partial class ComplexType : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ShippingAddress_Street = table.Column(type: "nvarchar(max)", nullable: true), - ShippingAddress_Location_Lat = table.Column(type: "float", nullable: false), - ShippingAddress_Location_Lng = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Orders"); - } - } -} diff --git a/src/DbContextExtensionsExamples/Migrations/20251215073408_Discriminator.Designer.cs b/src/DbContextExtensionsExamples/Migrations/20251215073408_Discriminator.Designer.cs deleted file mode 100644 index 593ad01..0000000 --- a/src/DbContextExtensionsExamples/Migrations/20251215073408_Discriminator.Designer.cs +++ /dev/null @@ -1,185 +0,0 @@ -// -using System; -using System.Collections.Generic; -using DbContextExtensionsExamples; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace DbContextExtensionsExamples.Migrations -{ - [DbContext(typeof(DemoDbContext))] - [Migration("20251215073408_Discriminator")] - partial class Discriminator - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("DbContextExtensionsExamples.Blog", b => - { - b.Property("BlogId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("BlogId")); - - b.Property("Discriminator") - .IsRequired() - .HasMaxLength(8) - .HasColumnType("nvarchar(8)"); - - b.Property("Url") - .HasColumnType("nvarchar(max)"); - - b.HasKey("BlogId"); - - b.ToTable("Blogs"); - - b.HasDiscriminator("Discriminator").HasValue("Blog"); - - b.UseTphMappingStrategy(); - }); - - modelBuilder.Entity("DbContextExtensionsExamples.Entities.CompositeKeyRow", b => - { - b.Property("Id1") - .HasColumnType("int"); - - b.Property("Id2") - .HasColumnType("int"); - - b.Property("Column1") - .HasColumnType("int"); - - b.Property("Column2") - .HasColumnType("nvarchar(max)"); - - b.Property("Column3") - .HasColumnType("datetime2"); - - b.HasKey("Id1", "Id2"); - - b.ToTable("CompositeKeyRows"); - }); - - modelBuilder.Entity("DbContextExtensionsExamples.Entities.ConfigurationEntry", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasColumnName("Id1") - .HasDefaultValueSql("newsequentialid()"); - - b.Property("CreatedDateTime") - .HasColumnType("datetimeoffset"); - - b.Property("Description") - .HasColumnType("nvarchar(max)"); - - b.Property("IsSensitive") - .HasColumnType("bit"); - - b.Property("Key") - .HasColumnType("nvarchar(max)") - .HasColumnName("Key1"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .ValueGeneratedOnAddOrUpdate() - .HasColumnType("rowversion"); - - b.Property("SeasonAsInt") - .HasColumnType("int"); - - b.Property("SeasonAsString") - .HasColumnType("nvarchar(max)"); - - b.Property("UpdatedDateTime") - .HasColumnType("datetimeoffset"); - - b.Property("Value") - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("ConfigurationEntries"); - }); - - modelBuilder.Entity("DbContextExtensionsExamples.Entities.Row", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Column1") - .HasColumnType("int"); - - b.Property("Column2") - .HasColumnType("nvarchar(max)"); - - b.Property("Column3") - .HasColumnType("datetime2"); - - b.HasKey("Id"); - - b.ToTable("Rows"); - }); - - modelBuilder.Entity("DbContextExtensionsExamples.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.ComplexProperty>("ShippingAddress", "DbContextExtensionsExamples.Order.ShippingAddress#Address", b1 => - { - b1.IsRequired(); - - b1.Property("Street") - .HasColumnType("nvarchar(max)"); - - b1.ComplexProperty>("Location", "DbContextExtensionsExamples.Order.ShippingAddress#Address.Location#Location", b2 => - { - b2.IsRequired(); - - b2.Property("Lat") - .HasColumnType("float"); - - b2.Property("Lng") - .HasColumnType("float"); - }); - }); - - b.HasKey("Id"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("DbContextExtensionsExamples.RssBlog", b => - { - b.HasBaseType("DbContextExtensionsExamples.Blog"); - - b.Property("RssUrl") - .HasColumnType("nvarchar(max)"); - - b.HasDiscriminator().HasValue("RssBlog"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/DbContextExtensionsExamples/Migrations/20251215073408_Discriminator.cs b/src/DbContextExtensionsExamples/Migrations/20251215073408_Discriminator.cs deleted file mode 100644 index a5afec4..0000000 --- a/src/DbContextExtensionsExamples/Migrations/20251215073408_Discriminator.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace DbContextExtensionsExamples.Migrations -{ - /// - public partial class Discriminator : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Blogs", - columns: table => new - { - BlogId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Url = table.Column(type: "nvarchar(max)", nullable: true), - Discriminator = table.Column(type: "nvarchar(8)", maxLength: 8, nullable: false), - RssUrl = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Blogs", x => x.BlogId); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Blogs"); - } - } -} diff --git a/src/DbContextExtensionsExamples/Migrations/20260308062025_Init.Designer.cs b/src/DbContextExtensionsExamples/Migrations/20260308062025_Init.Designer.cs new file mode 100644 index 0000000..73dbecb --- /dev/null +++ b/src/DbContextExtensionsExamples/Migrations/20260308062025_Init.Designer.cs @@ -0,0 +1,475 @@ +// +using System; +using System.Collections.Generic; +using DbContextExtensionsExamples; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DbContextExtensionsExamples.Migrations +{ + [DbContext(typeof(DemoDbContext))] + [Migration("20260308062025_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DbContextExtensionsExamples.Blog", b => + { + b.Property("BlogId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("BlogId")); + + b.Property("Discriminator") + .IsRequired() + .HasMaxLength(8) + .HasColumnType("nvarchar(8)"); + + b.Property("Url") + .HasColumnType("nvarchar(max)"); + + b.HasKey("BlogId"); + + b.ToTable("Blogs"); + + b.HasDiscriminator().HasValue("Blog"); + + b.UseTphMappingStrategy(); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.ComplexOwnedTypeOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.ComplexProperty(typeof(Dictionary), "ComplexShippingAddress", "DbContextExtensionsExamples.Entities.ComplexOwnedTypeOrder.ComplexShippingAddress#ComplexTypeAddress", b1 => + { + b1.IsRequired(); + + b1.Property("Street") + .HasColumnType("nvarchar(max)"); + + b1.ComplexProperty(typeof(Dictionary), "Location", "DbContextExtensionsExamples.Entities.ComplexOwnedTypeOrder.ComplexShippingAddress#ComplexTypeAddress.Location#ComplexTypeLocation", b2 => + { + b2.Property("Lat") + .HasColumnType("float"); + + b2.Property("Lng") + .HasColumnType("float"); + }); + }); + + b.HasKey("Id"); + + b.ToTable("ComplexOwnedTypeOrders"); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.ComplexTypeOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.ComplexProperty(typeof(Dictionary), "ShippingAddress", "DbContextExtensionsExamples.Entities.ComplexTypeOrder.ShippingAddress#ComplexTypeAddress", b1 => + { + b1.IsRequired(); + + b1.Property("Street") + .HasColumnType("nvarchar(max)"); + + b1.ComplexProperty(typeof(Dictionary), "Location", "DbContextExtensionsExamples.Entities.ComplexTypeOrder.ShippingAddress#ComplexTypeAddress.Location#ComplexTypeLocation", b2 => + { + b2.Property("Lat") + .HasColumnType("float"); + + b2.Property("Lng") + .HasColumnType("float"); + }); + }); + + b.HasKey("Id"); + + b.ToTable("ComplexTypeOrders"); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.CompositeKeyRow", b => + { + b.Property("Id1") + .HasColumnType("int"); + + b.Property("Id2") + .HasColumnType("int"); + + b.Property("Column1") + .HasColumnType("int"); + + b.Property("Column2") + .HasColumnType("nvarchar(max)"); + + b.Property("Column3") + .HasColumnType("datetime2"); + + b.HasKey("Id1", "Id2"); + + b.ToTable("CompositeKeyRows"); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.ConfigurationEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasColumnName("Id1") + .HasDefaultValueSql("newsequentialid()"); + + b.Property("CreatedDateTime") + .HasColumnType("datetimeoffset"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("IsSensitive") + .HasColumnType("bit"); + + b.Property("Key") + .HasColumnType("nvarchar(max)") + .HasColumnName("Key1"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("SeasonAsInt") + .HasColumnType("int"); + + b.Property("SeasonAsString") + .HasColumnType("nvarchar(max)"); + + b.Property("UpdatedDateTime") + .HasColumnType("datetimeoffset"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("ConfigurationEntries"); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.JsonComplexOwnedTypeOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.ComplexProperty(typeof(Dictionary), "ComplexShippingAddress", "DbContextExtensionsExamples.Entities.JsonComplexOwnedTypeOrder.ComplexShippingAddress#ComplexTypeAddress", b1 => + { + b1.IsRequired(); + + b1.Property("Street"); + + b1.ComplexProperty(typeof(Dictionary), "Location", "DbContextExtensionsExamples.Entities.JsonComplexOwnedTypeOrder.ComplexShippingAddress#ComplexTypeAddress.Location#ComplexTypeLocation", b2 => + { + b2.Property("Lat"); + + b2.Property("Lng"); + + b2.HasJsonPropertyName("xxx"); + }); + + b1.ToJson("ComplexShippingAddress"); + }); + + b.HasKey("Id"); + + b.ToTable("JsonComplexOwnedTypeOrders"); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.JsonComplexTypeOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.ComplexProperty(typeof(Dictionary), "ShippingAddress", "DbContextExtensionsExamples.Entities.JsonComplexTypeOrder.ShippingAddress#ComplexTypeAddress", b1 => + { + b1.IsRequired(); + + b1.Property("Street"); + + b1.ComplexProperty(typeof(Dictionary), "Location", "DbContextExtensionsExamples.Entities.JsonComplexTypeOrder.ShippingAddress#ComplexTypeAddress.Location#ComplexTypeLocation", b2 => + { + b2.Property("Lat"); + + b2.Property("Lng"); + + b2.HasJsonPropertyName("xxx"); + }); + + b1.ToJson("ShippingAddress"); + }); + + b.HasKey("Id"); + + b.ToTable("JsonComplexTypeOrders"); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.JsonOwnedTypeOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.HasKey("Id"); + + b.ToTable("JsonOwnedTypeOrders"); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.OwnedTypeOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.HasKey("Id"); + + b.ToTable("OwnedTypeOrders"); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.Row", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Column1") + .HasColumnType("int"); + + b.Property("Column2") + .HasColumnType("nvarchar(max)"); + + b.Property("Column3") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.ToTable("Rows"); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.RssBlog", b => + { + b.HasBaseType("DbContextExtensionsExamples.Blog"); + + b.Property("RssUrl") + .HasColumnType("nvarchar(max)"); + + b.HasDiscriminator().HasValue("RssBlog"); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.ComplexOwnedTypeOrder", b => + { + b.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeAddress", "OwnedShippingAddress", b1 => + { + b1.Property("ComplexOwnedTypeOrderId") + .HasColumnType("int"); + + b1.Property("Street") + .HasColumnType("nvarchar(max)"); + + b1.HasKey("ComplexOwnedTypeOrderId"); + + b1.ToTable("ComplexOwnedTypeOrders"); + + b1.WithOwner() + .HasForeignKey("ComplexOwnedTypeOrderId"); + + b1.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeLocation", "Location", b2 => + { + b2.Property("OwnedTypeAddressComplexOwnedTypeOrderId") + .HasColumnType("int"); + + b2.Property("Lat") + .HasColumnType("float"); + + b2.Property("Lng") + .HasColumnType("float"); + + b2.HasKey("OwnedTypeAddressComplexOwnedTypeOrderId"); + + b2.ToTable("ComplexOwnedTypeOrders"); + + b2.WithOwner() + .HasForeignKey("OwnedTypeAddressComplexOwnedTypeOrderId"); + }); + + b1.Navigation("Location") + .IsRequired(); + }); + + b.Navigation("OwnedShippingAddress") + .IsRequired(); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.JsonComplexOwnedTypeOrder", b => + { + b.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeAddress", "OwnedShippingAddress", b1 => + { + b1.Property("JsonComplexOwnedTypeOrderId"); + + b1.Property("Street"); + + b1.HasKey("JsonComplexOwnedTypeOrderId"); + + b1.ToTable("JsonComplexOwnedTypeOrders"); + + b1.ToJson("OwnedShippingAddress"); + + b1.WithOwner() + .HasForeignKey("JsonComplexOwnedTypeOrderId"); + + b1.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeLocation", "Location", b2 => + { + b2.Property("OwnedTypeAddressJsonComplexOwnedTypeOrderId"); + + b2.Property("Lat"); + + b2.Property("Lng"); + + b2.HasKey("OwnedTypeAddressJsonComplexOwnedTypeOrderId"); + + b2.ToTable("JsonComplexOwnedTypeOrders"); + + b2.HasJsonPropertyName("xxx"); + + b2.WithOwner() + .HasForeignKey("OwnedTypeAddressJsonComplexOwnedTypeOrderId"); + }); + + b1.Navigation("Location") + .IsRequired(); + }); + + b.Navigation("OwnedShippingAddress") + .IsRequired(); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.JsonOwnedTypeOrder", b => + { + b.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeAddress", "ShippingAddress", b1 => + { + b1.Property("JsonOwnedTypeOrderId"); + + b1.Property("Street"); + + b1.HasKey("JsonOwnedTypeOrderId"); + + b1.ToTable("JsonOwnedTypeOrders"); + + b1.ToJson("ShippingAddress"); + + b1.WithOwner() + .HasForeignKey("JsonOwnedTypeOrderId"); + + b1.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeLocation", "Location", b2 => + { + b2.Property("OwnedTypeAddressJsonOwnedTypeOrderId"); + + b2.Property("Lat"); + + b2.Property("Lng"); + + b2.HasKey("OwnedTypeAddressJsonOwnedTypeOrderId"); + + b2.ToTable("JsonOwnedTypeOrders"); + + b2.HasJsonPropertyName("xxx"); + + b2.WithOwner() + .HasForeignKey("OwnedTypeAddressJsonOwnedTypeOrderId"); + }); + + b1.Navigation("Location") + .IsRequired(); + }); + + b.Navigation("ShippingAddress") + .IsRequired(); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.OwnedTypeOrder", b => + { + b.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeAddress", "ShippingAddress", b1 => + { + b1.Property("OwnedTypeOrderId") + .HasColumnType("int"); + + b1.Property("Street") + .HasColumnType("nvarchar(max)"); + + b1.HasKey("OwnedTypeOrderId"); + + b1.ToTable("OwnedTypeOrders"); + + b1.WithOwner() + .HasForeignKey("OwnedTypeOrderId"); + + b1.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeLocation", "Location", b2 => + { + b2.Property("OwnedTypeAddressOwnedTypeOrderId") + .HasColumnType("int"); + + b2.Property("Lat") + .HasColumnType("float"); + + b2.Property("Lng") + .HasColumnType("float"); + + b2.HasKey("OwnedTypeAddressOwnedTypeOrderId"); + + b2.ToTable("OwnedTypeOrders"); + + b2.WithOwner() + .HasForeignKey("OwnedTypeAddressOwnedTypeOrderId"); + }); + + b1.Navigation("Location") + .IsRequired(); + }); + + b.Navigation("ShippingAddress") + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DbContextExtensionsExamples/Migrations/20260308062025_Init.cs b/src/DbContextExtensionsExamples/Migrations/20260308062025_Init.cs new file mode 100644 index 0000000..f08f617 --- /dev/null +++ b/src/DbContextExtensionsExamples/Migrations/20260308062025_Init.cs @@ -0,0 +1,202 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DbContextExtensionsExamples.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Blogs", + columns: table => new + { + BlogId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Url = table.Column(type: "nvarchar(max)", nullable: true), + Discriminator = table.Column(type: "nvarchar(8)", maxLength: 8, nullable: false), + RssUrl = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Blogs", x => x.BlogId); + }); + + migrationBuilder.CreateTable( + name: "ComplexOwnedTypeOrders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + OwnedShippingAddress_Street = table.Column(type: "nvarchar(max)", nullable: true), + OwnedShippingAddress_Location_Lat = table.Column(type: "float", nullable: false), + OwnedShippingAddress_Location_Lng = table.Column(type: "float", nullable: false), + ComplexShippingAddress_Street = table.Column(type: "nvarchar(max)", nullable: true), + ComplexShippingAddress_Location_Lat = table.Column(type: "float", nullable: true), + ComplexShippingAddress_Location_Lng = table.Column(type: "float", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ComplexOwnedTypeOrders", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ComplexTypeOrders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShippingAddress_Street = table.Column(type: "nvarchar(max)", nullable: true), + ShippingAddress_Location_Lat = table.Column(type: "float", nullable: true), + ShippingAddress_Location_Lng = table.Column(type: "float", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ComplexTypeOrders", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CompositeKeyRows", + columns: table => new + { + Id1 = table.Column(type: "int", nullable: false), + Id2 = table.Column(type: "int", nullable: false), + Column1 = table.Column(type: "int", nullable: false), + Column2 = table.Column(type: "nvarchar(max)", nullable: true), + Column3 = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CompositeKeyRows", x => new { x.Id1, x.Id2 }); + }); + + migrationBuilder.CreateTable( + name: "ConfigurationEntries", + columns: table => new + { + Id1 = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "newsequentialid()"), + RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: true), + CreatedDateTime = table.Column(type: "datetimeoffset", nullable: false), + UpdatedDateTime = table.Column(type: "datetimeoffset", nullable: true), + Key1 = table.Column(type: "nvarchar(max)", nullable: true), + Value = table.Column(type: "nvarchar(max)", nullable: true), + Description = table.Column(type: "nvarchar(max)", nullable: true), + IsSensitive = table.Column(type: "bit", nullable: false), + SeasonAsInt = table.Column(type: "int", nullable: true), + SeasonAsString = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ConfigurationEntries", x => x.Id1); + }); + + migrationBuilder.CreateTable( + name: "JsonComplexOwnedTypeOrders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComplexShippingAddress = table.Column(type: "nvarchar(max)", nullable: false), + OwnedShippingAddress = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_JsonComplexOwnedTypeOrders", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "JsonComplexTypeOrders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShippingAddress = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_JsonComplexTypeOrders", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "JsonOwnedTypeOrders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShippingAddress = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_JsonOwnedTypeOrders", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "OwnedTypeOrders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShippingAddress_Street = table.Column(type: "nvarchar(max)", nullable: true), + ShippingAddress_Location_Lat = table.Column(type: "float", nullable: false), + ShippingAddress_Location_Lng = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OwnedTypeOrders", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Rows", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Column1 = table.Column(type: "int", nullable: false), + Column2 = table.Column(type: "nvarchar(max)", nullable: true), + Column3 = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Rows", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Blogs"); + + migrationBuilder.DropTable( + name: "ComplexOwnedTypeOrders"); + + migrationBuilder.DropTable( + name: "ComplexTypeOrders"); + + migrationBuilder.DropTable( + name: "CompositeKeyRows"); + + migrationBuilder.DropTable( + name: "ConfigurationEntries"); + + migrationBuilder.DropTable( + name: "JsonComplexOwnedTypeOrders"); + + migrationBuilder.DropTable( + name: "JsonComplexTypeOrders"); + + migrationBuilder.DropTable( + name: "JsonOwnedTypeOrders"); + + migrationBuilder.DropTable( + name: "OwnedTypeOrders"); + + migrationBuilder.DropTable( + name: "Rows"); + } + } +} diff --git a/src/DbContextExtensionsExamples/Migrations/DemoDbContextModelSnapshot.cs b/src/DbContextExtensionsExamples/Migrations/DemoDbContextModelSnapshot.cs index 18dc2e8..6c5042e 100644 --- a/src/DbContextExtensionsExamples/Migrations/DemoDbContextModelSnapshot.cs +++ b/src/DbContextExtensionsExamples/Migrations/DemoDbContextModelSnapshot.cs @@ -18,7 +18,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") + .HasAnnotation("ProductVersion", "10.0.0") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); @@ -43,11 +43,71 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Blogs"); - b.HasDiscriminator("Discriminator").HasValue("Blog"); + b.HasDiscriminator().HasValue("Blog"); b.UseTphMappingStrategy(); }); + modelBuilder.Entity("DbContextExtensionsExamples.Entities.ComplexOwnedTypeOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.ComplexProperty(typeof(Dictionary), "ComplexShippingAddress", "DbContextExtensionsExamples.Entities.ComplexOwnedTypeOrder.ComplexShippingAddress#ComplexTypeAddress", b1 => + { + b1.IsRequired(); + + b1.Property("Street") + .HasColumnType("nvarchar(max)"); + + b1.ComplexProperty(typeof(Dictionary), "Location", "DbContextExtensionsExamples.Entities.ComplexOwnedTypeOrder.ComplexShippingAddress#ComplexTypeAddress.Location#ComplexTypeLocation", b2 => + { + b2.Property("Lat") + .HasColumnType("float"); + + b2.Property("Lng") + .HasColumnType("float"); + }); + }); + + b.HasKey("Id"); + + b.ToTable("ComplexOwnedTypeOrders"); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.ComplexTypeOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.ComplexProperty(typeof(Dictionary), "ShippingAddress", "DbContextExtensionsExamples.Entities.ComplexTypeOrder.ShippingAddress#ComplexTypeAddress", b1 => + { + b1.IsRequired(); + + b1.Property("Street") + .HasColumnType("nvarchar(max)"); + + b1.ComplexProperty(typeof(Dictionary), "Location", "DbContextExtensionsExamples.Entities.ComplexTypeOrder.ShippingAddress#ComplexTypeAddress.Location#ComplexTypeLocation", b2 => + { + b2.Property("Lat") + .HasColumnType("float"); + + b2.Property("Lng") + .HasColumnType("float"); + }); + }); + + b.HasKey("Id"); + + b.ToTable("ComplexTypeOrders"); + }); + modelBuilder.Entity("DbContextExtensionsExamples.Entities.CompositeKeyRow", b => { b.Property("Id1") @@ -113,6 +173,94 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("ConfigurationEntries"); }); + modelBuilder.Entity("DbContextExtensionsExamples.Entities.JsonComplexOwnedTypeOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.ComplexProperty(typeof(Dictionary), "ComplexShippingAddress", "DbContextExtensionsExamples.Entities.JsonComplexOwnedTypeOrder.ComplexShippingAddress#ComplexTypeAddress", b1 => + { + b1.IsRequired(); + + b1.Property("Street"); + + b1.ComplexProperty(typeof(Dictionary), "Location", "DbContextExtensionsExamples.Entities.JsonComplexOwnedTypeOrder.ComplexShippingAddress#ComplexTypeAddress.Location#ComplexTypeLocation", b2 => + { + b2.Property("Lat"); + + b2.Property("Lng"); + + b2.HasJsonPropertyName("xxx"); + }); + + b1.ToJson("ComplexShippingAddress"); + }); + + b.HasKey("Id"); + + b.ToTable("JsonComplexOwnedTypeOrders"); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.JsonComplexTypeOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.ComplexProperty(typeof(Dictionary), "ShippingAddress", "DbContextExtensionsExamples.Entities.JsonComplexTypeOrder.ShippingAddress#ComplexTypeAddress", b1 => + { + b1.IsRequired(); + + b1.Property("Street"); + + b1.ComplexProperty(typeof(Dictionary), "Location", "DbContextExtensionsExamples.Entities.JsonComplexTypeOrder.ShippingAddress#ComplexTypeAddress.Location#ComplexTypeLocation", b2 => + { + b2.Property("Lat"); + + b2.Property("Lng"); + + b2.HasJsonPropertyName("xxx"); + }); + + b1.ToJson("ShippingAddress"); + }); + + b.HasKey("Id"); + + b.ToTable("JsonComplexTypeOrders"); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.JsonOwnedTypeOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.HasKey("Id"); + + b.ToTable("JsonOwnedTypeOrders"); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.OwnedTypeOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.HasKey("Id"); + + b.ToTable("OwnedTypeOrders"); + }); + modelBuilder.Entity("DbContextExtensionsExamples.Entities.Row", b => { b.Property("Id") @@ -135,46 +283,188 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Rows"); }); - modelBuilder.Entity("DbContextExtensionsExamples.Order", b => + modelBuilder.Entity("DbContextExtensionsExamples.RssBlog", b => { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); + b.HasBaseType("DbContextExtensionsExamples.Blog"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("RssUrl") + .HasColumnType("nvarchar(max)"); + + b.HasDiscriminator().HasValue("RssBlog"); + }); - b.ComplexProperty>("ShippingAddress", "DbContextExtensionsExamples.Order.ShippingAddress#Address", b1 => + modelBuilder.Entity("DbContextExtensionsExamples.Entities.ComplexOwnedTypeOrder", b => + { + b.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeAddress", "OwnedShippingAddress", b1 => { - b1.IsRequired(); + b1.Property("ComplexOwnedTypeOrderId") + .HasColumnType("int"); b1.Property("Street") .HasColumnType("nvarchar(max)"); - b1.ComplexProperty>("Location", "DbContextExtensionsExamples.Order.ShippingAddress#Address.Location#Location", b2 => + b1.HasKey("ComplexOwnedTypeOrderId"); + + b1.ToTable("ComplexOwnedTypeOrders"); + + b1.WithOwner() + .HasForeignKey("ComplexOwnedTypeOrderId"); + + b1.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeLocation", "Location", b2 => { - b2.IsRequired(); + b2.Property("OwnedTypeAddressComplexOwnedTypeOrderId") + .HasColumnType("int"); b2.Property("Lat") .HasColumnType("float"); b2.Property("Lng") .HasColumnType("float"); + + b2.HasKey("OwnedTypeAddressComplexOwnedTypeOrderId"); + + b2.ToTable("ComplexOwnedTypeOrders"); + + b2.WithOwner() + .HasForeignKey("OwnedTypeAddressComplexOwnedTypeOrderId"); }); + + b1.Navigation("Location") + .IsRequired(); }); - b.HasKey("Id"); + b.Navigation("OwnedShippingAddress") + .IsRequired(); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.JsonComplexOwnedTypeOrder", b => + { + b.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeAddress", "OwnedShippingAddress", b1 => + { + b1.Property("JsonComplexOwnedTypeOrderId"); + + b1.Property("Street"); + + b1.HasKey("JsonComplexOwnedTypeOrderId"); + + b1.ToTable("JsonComplexOwnedTypeOrders"); + + b1.ToJson("OwnedShippingAddress"); + + b1.WithOwner() + .HasForeignKey("JsonComplexOwnedTypeOrderId"); + + b1.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeLocation", "Location", b2 => + { + b2.Property("OwnedTypeAddressJsonComplexOwnedTypeOrderId"); + + b2.Property("Lat"); + + b2.Property("Lng"); + + b2.HasKey("OwnedTypeAddressJsonComplexOwnedTypeOrderId"); + + b2.ToTable("JsonComplexOwnedTypeOrders"); - b.ToTable("Orders"); + b2.HasJsonPropertyName("xxx"); + + b2.WithOwner() + .HasForeignKey("OwnedTypeAddressJsonComplexOwnedTypeOrderId"); + }); + + b1.Navigation("Location") + .IsRequired(); + }); + + b.Navigation("OwnedShippingAddress") + .IsRequired(); }); - modelBuilder.Entity("DbContextExtensionsExamples.RssBlog", b => + modelBuilder.Entity("DbContextExtensionsExamples.Entities.JsonOwnedTypeOrder", b => { - b.HasBaseType("DbContextExtensionsExamples.Blog"); + b.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeAddress", "ShippingAddress", b1 => + { + b1.Property("JsonOwnedTypeOrderId"); - b.Property("RssUrl") - .HasColumnType("nvarchar(max)"); + b1.Property("Street"); - b.HasDiscriminator().HasValue("RssBlog"); + b1.HasKey("JsonOwnedTypeOrderId"); + + b1.ToTable("JsonOwnedTypeOrders"); + + b1.ToJson("ShippingAddress"); + + b1.WithOwner() + .HasForeignKey("JsonOwnedTypeOrderId"); + + b1.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeLocation", "Location", b2 => + { + b2.Property("OwnedTypeAddressJsonOwnedTypeOrderId"); + + b2.Property("Lat"); + + b2.Property("Lng"); + + b2.HasKey("OwnedTypeAddressJsonOwnedTypeOrderId"); + + b2.ToTable("JsonOwnedTypeOrders"); + + b2.HasJsonPropertyName("xxx"); + + b2.WithOwner() + .HasForeignKey("OwnedTypeAddressJsonOwnedTypeOrderId"); + }); + + b1.Navigation("Location") + .IsRequired(); + }); + + b.Navigation("ShippingAddress") + .IsRequired(); + }); + + modelBuilder.Entity("DbContextExtensionsExamples.Entities.OwnedTypeOrder", b => + { + b.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeAddress", "ShippingAddress", b1 => + { + b1.Property("OwnedTypeOrderId") + .HasColumnType("int"); + + b1.Property("Street") + .HasColumnType("nvarchar(max)"); + + b1.HasKey("OwnedTypeOrderId"); + + b1.ToTable("OwnedTypeOrders"); + + b1.WithOwner() + .HasForeignKey("OwnedTypeOrderId"); + + b1.OwnsOne("DbContextExtensionsExamples.Entities.OwnedTypeLocation", "Location", b2 => + { + b2.Property("OwnedTypeAddressOwnedTypeOrderId") + .HasColumnType("int"); + + b2.Property("Lat") + .HasColumnType("float"); + + b2.Property("Lng") + .HasColumnType("float"); + + b2.HasKey("OwnedTypeAddressOwnedTypeOrderId"); + + b2.ToTable("OwnedTypeOrders"); + + b2.WithOwner() + .HasForeignKey("OwnedTypeAddressOwnedTypeOrderId"); + }); + + b1.Navigation("Location") + .IsRequired(); + }); + + b.Navigation("ShippingAddress") + .IsRequired(); }); #pragma warning restore 612, 618 } diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 1ae0646..b8493ed 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,6 +1,6 @@ - net8.0 + net10.0 8.23.0 9.0.0-preview.1 10.0.0-preview.1 diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BaseTest.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BaseTest.cs index 06b778f..8314847 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BaseTest.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BaseTest.cs @@ -1,6 +1,7 @@ using EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests.Database; using EntityFrameworkCore.SqlServer.SimpleBulks.Extensions; using Microsoft.Data.SqlClient; +using System.Text.Json; using Xunit.Abstractions; namespace EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests.ConnectionExtensions; @@ -35,11 +36,20 @@ protected BaseTest(ITestOutputHelper output, SqlServerFixture fixture, string db .ConfigureComplexProperty(x => x.ComplexShippingAddress.Location) .ConfigureComplexProperty(x => x.OwnedShippingAddress) .ConfigureComplexProperty(x => x.OwnedShippingAddress.Location) - .ConfigurePropertyConversion(x => x.SeasonAsString, y => y.ToString(), z => (Season)Enum.Parse(typeof(Season), z)); + .ConfigurePropertyConversion(x => x.SeasonAsString, y => y.ToString(), z => (Season)Enum.Parse(typeof(Season), z)) + .ConfigureJsonProperty(x => x.JsonOwnedShippingAddress, y => JsonSerializer.Serialize(y)); if (_enableDiscriminator) { config.ConfigureDiscriminator("Discriminator", value: "SingleKeyRow", columnName: "Discriminator", columnType: _context.GetDiscriminator(typeof(SingleKeyRow)).ColumnType); + + config + .ConfigureComplexProperty(x => x.JsonComplexShippingAddress) + .ConfigureComplexProperty(x => x.JsonComplexShippingAddress.Location); + } + else + { + config.ConfigureJsonProperty(x => x.JsonComplexShippingAddress, y => JsonSerializer.Serialize(y)); } }); @@ -65,6 +75,8 @@ protected BaseTest(ITestOutputHelper output, SqlServerFixture fixture, string db .TableName("ConfigurationEntry") .PrimaryKeys(x => x.Id) .OutputId(x => x.Id, OutputIdMode.ServerGenerated) + .ConfigureProperty(x => x.Id, columnName: "Id1") + .ConfigureProperty(x => x.Key, columnName: "Key1") .ConfigureProperty(x => x.RowVersion, readOnly: true); if (_enableDiscriminator) diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkDeleteAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkDeleteAsyncTests.cs index 171a1e4..fc918cb 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkDeleteAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkDeleteAsyncTests.cs @@ -33,6 +33,24 @@ public BulkDeleteAsyncTests(ITestOutputHelper output, SqlServerFixture fixture) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkDeleteTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkDeleteTests.cs index 838ef02..4fc5211 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkDeleteTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkDeleteTests.cs @@ -33,6 +33,24 @@ public BulkDeleteTests(ITestOutputHelper output, SqlServerFixture fixture) : bas } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkInsertAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkInsertAsyncTests.cs index 3d5cc00..122d16d 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkInsertAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkInsertAsyncTests.cs @@ -43,6 +43,24 @@ public async Task BulkInsert_Without_Transaction(int length, bool useLinq) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -96,7 +114,9 @@ await connectionContext.BulkInsertAsync(rows, row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: options); @@ -116,7 +136,9 @@ await connectionContext.BulkInsertAsync(rows, "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options: options); @@ -142,6 +164,12 @@ await connectionContext.BulkInsertAsync(compositeKeyRows, Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkInsertTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkInsertTests.cs index 73a24cb..f6a9aba 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkInsertTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkInsertTests.cs @@ -43,6 +43,24 @@ public void BulkInsert_Without_Transaction(int length, bool useLinq) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -96,7 +114,9 @@ public void BulkInsert_Without_Transaction(int length, bool useLinq) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: options); @@ -116,7 +136,9 @@ public void BulkInsert_Without_Transaction(int length, bool useLinq) "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options: options); @@ -142,6 +164,12 @@ public void BulkInsert_Without_Transaction(int length, bool useLinq) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkMergeAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkMergeAsyncTests.cs index 9e50770..94a6019 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkMergeAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkMergeAsyncTests.cs @@ -39,6 +39,24 @@ private async Task SeedData(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -110,6 +128,24 @@ public async Task BulkMerge_Using_Linq_With_Transaction(int length, int insertLe Lng = -80.0 } }; + row.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + row.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; } foreach (var row in compositeKeyRows) @@ -139,6 +175,24 @@ public async Task BulkMerge_Using_Linq_With_Transaction(int length, int insertLe } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -175,7 +229,9 @@ public async Task BulkMerge_Using_Linq_With_Transaction(int length, int insertLe row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, row => new { @@ -189,7 +245,9 @@ public async Task BulkMerge_Using_Linq_With_Transaction(int length, int insertLe row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: new BulkMergeOptions() { @@ -234,6 +292,12 @@ public async Task BulkMerge_Using_Linq_With_Transaction(int length, int insertLe Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -287,6 +351,24 @@ public async Task BulkMerge_Using_Dynamic_String_With_Transaction(int length, in Lng = -80.0 } }; + row.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + row.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; } foreach (var row in compositeKeyRows) @@ -316,6 +398,24 @@ public async Task BulkMerge_Using_Dynamic_String_With_Transaction(int length, in } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -351,7 +451,9 @@ public async Task BulkMerge_Using_Dynamic_String_With_Transaction(int length, in "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], [ "Column1", @@ -364,7 +466,9 @@ public async Task BulkMerge_Using_Dynamic_String_With_Transaction(int length, in "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options: new BulkMergeOptions() { @@ -408,6 +512,12 @@ public async Task BulkMerge_Using_Dynamic_String_With_Transaction(int length, in Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkMergeTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkMergeTests.cs index 4861ddd..693649b 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkMergeTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkMergeTests.cs @@ -39,6 +39,24 @@ private void SeedData(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -110,6 +128,24 @@ public void BulkMerge_Using_Linq_With_Transaction(int length, int insertLength) Lng = -80.0 } }; + row.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + row.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; } foreach (var row in compositeKeyRows) @@ -139,6 +175,24 @@ public void BulkMerge_Using_Linq_With_Transaction(int length, int insertLength) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -175,7 +229,9 @@ public void BulkMerge_Using_Linq_With_Transaction(int length, int insertLength) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, row => new { @@ -189,7 +245,9 @@ public void BulkMerge_Using_Linq_With_Transaction(int length, int insertLength) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: new BulkMergeOptions() { @@ -234,6 +292,12 @@ public void BulkMerge_Using_Linq_With_Transaction(int length, int insertLength) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -316,6 +380,24 @@ public void BulkMerge_Using_Dynamic_String_With_Transaction(int length, int inse } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -351,7 +433,9 @@ public void BulkMerge_Using_Dynamic_String_With_Transaction(int length, int inse "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], [ "Column1", @@ -364,7 +448,9 @@ public void BulkMerge_Using_Dynamic_String_With_Transaction(int length, int inse "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options: new BulkMergeOptions() { @@ -408,6 +494,12 @@ public void BulkMerge_Using_Dynamic_String_With_Transaction(int length, int inse Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkUpdateAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkUpdateAsyncTests.cs index 7993e5a..18567a8 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkUpdateAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkUpdateAsyncTests.cs @@ -35,6 +35,24 @@ public BulkUpdateAsyncTests(ITestOutputHelper output, SqlServerFixture fixture) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -96,6 +114,24 @@ public async Task BulkUpdate_PrimaryKeys(bool useLinq) Lng = -80.0 } }; + row.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + row.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; } foreach (var row in compositeKeyRows) @@ -121,7 +157,9 @@ await connectionContext.BulkUpdateAsync(rows, row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: updateOptions); @@ -140,7 +178,9 @@ await connectionContext.BulkUpdateAsync(rows, "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options: updateOptions); @@ -165,6 +205,12 @@ await connectionContext.BulkUpdateAsync(compositeKeyRows, Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -206,6 +252,24 @@ public async Task BulkUpdate_SpecifiedKeys(bool useLinq) Lng = -80.0 } }; + row.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + row.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; } foreach (var row in compositeKeyRows) @@ -231,7 +295,9 @@ await connectionContext.BulkUpdateAsync(rows, x => x.Id, row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: updateOptions); @@ -250,7 +316,9 @@ await connectionContext.BulkUpdateAsync(rows, ["Id"], "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options: updateOptions); @@ -275,6 +343,12 @@ await connectionContext.BulkUpdateAsync(compositeKeyRows, ["Id1", "Id2"], Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkUpdateTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkUpdateTests.cs index 4ce9223..975aca9 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkUpdateTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BulkUpdateTests.cs @@ -35,6 +35,24 @@ public BulkUpdateTests(ITestOutputHelper output, SqlServerFixture fixture) : bas } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -96,6 +114,24 @@ public void BulkUpdate_PrimaryKeys(bool useLinq) Lng = -80.0 } }; + row.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + row.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; } foreach (var row in compositeKeyRows) @@ -121,7 +157,9 @@ public void BulkUpdate_PrimaryKeys(bool useLinq) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: updateOptions); @@ -140,7 +178,9 @@ public void BulkUpdate_PrimaryKeys(bool useLinq) "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options: updateOptions); @@ -165,6 +205,12 @@ public void BulkUpdate_PrimaryKeys(bool useLinq) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -206,6 +252,24 @@ public void BulkUpdate_SpecifiedKeys(bool useLinq) Lng = -80.0 } }; + row.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + row.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; } foreach (var row in compositeKeyRows) @@ -231,7 +295,9 @@ public void BulkUpdate_SpecifiedKeys(bool useLinq) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: updateOptions); @@ -250,7 +316,9 @@ public void BulkUpdate_SpecifiedKeys(bool useLinq) "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options: updateOptions); @@ -275,6 +343,12 @@ public void BulkUpdate_SpecifiedKeys(bool useLinq) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectDeleteAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectDeleteAsyncTests.cs index 56fbb57..d71f4ef 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectDeleteAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectDeleteAsyncTests.cs @@ -36,6 +36,24 @@ public DirectDeleteAsyncTests(ITestOutputHelper output, SqlServerFixture fixture } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectDeleteTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectDeleteTests.cs index 4b2a87f..064cada 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectDeleteTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectDeleteTests.cs @@ -36,6 +36,24 @@ public DirectDeleteTests(ITestOutputHelper output, SqlServerFixture fixture) : b } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectInsertAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectInsertAsyncTests.cs index 25a30ab..68fead3 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectInsertAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectInsertAsyncTests.cs @@ -35,6 +35,24 @@ public async Task DirectInsert_Using_Linq_Without_Transaction() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street 1", + Location = new OwnedTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street 1", + Location = new ComplexTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street 1", Location = new OwnedTypeLocation @@ -74,7 +92,9 @@ await connectionContext.DirectInsertAsync(row, row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: options); @@ -102,6 +122,12 @@ await connectionContext.DirectInsertAsync(compositeKeyRow, Assert.Equal(row.OwnedShippingAddress?.Street, dbRows[0].OwnedShippingAddress?.Street); Assert.Equal(row.OwnedShippingAddress?.Location?.Lat, dbRows[0].OwnedShippingAddress?.Location?.Lat); Assert.Equal(row.OwnedShippingAddress?.Location?.Lng, dbRows[0].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonComplexShippingAddress?.Street, dbRows[0].JsonComplexShippingAddress?.Street); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lat, dbRows[0].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lng, dbRows[0].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonOwnedShippingAddress?.Street, dbRows[0].JsonOwnedShippingAddress?.Street); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lat, dbRows[0].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lng, dbRows[0].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRow.Id1, dbCompositeKeyRows[0].Id1); Assert.Equal(compositeKeyRow.Id2, dbCompositeKeyRows[0].Id2); @@ -138,6 +164,24 @@ public async Task DirectInsert_Using_Linq_With_Transaction_Committed() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street 1", + Location = new OwnedTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street 1", + Location = new ComplexTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street 1", Location = new OwnedTypeLocation @@ -172,7 +216,9 @@ await connectionContext.DirectInsertAsync(row, row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: new BulkInsertOptions() { @@ -207,6 +253,12 @@ await connectionContext.DirectInsertAsync(compositeKeyRow, Assert.Equal(row.OwnedShippingAddress?.Street, dbRows[0].OwnedShippingAddress?.Street); Assert.Equal(row.OwnedShippingAddress?.Location?.Lat, dbRows[0].OwnedShippingAddress?.Location?.Lat); Assert.Equal(row.OwnedShippingAddress?.Location?.Lng, dbRows[0].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonComplexShippingAddress?.Street, dbRows[0].JsonComplexShippingAddress?.Street); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lat, dbRows[0].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lng, dbRows[0].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonOwnedShippingAddress?.Street, dbRows[0].JsonOwnedShippingAddress?.Street); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lat, dbRows[0].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lng, dbRows[0].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRow.Id1, dbCompositeKeyRows[0].Id1); Assert.Equal(compositeKeyRow.Id2, dbCompositeKeyRows[0].Id2); @@ -243,6 +295,24 @@ public async Task DirectInsert_Using_Linq_With_Transaction_RolledBack() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street 1", + Location = new OwnedTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street 1", + Location = new ComplexTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street 1", Location = new OwnedTypeLocation @@ -277,7 +347,9 @@ await connectionContext.DirectInsertAsync(row, row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: new BulkInsertOptions() { @@ -384,6 +456,24 @@ public async Task DirectInsert_Using_DynamicString() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street 1", + Location = new OwnedTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street 1", + Location = new ComplexTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street 1", Location = new OwnedTypeLocation @@ -422,7 +512,9 @@ await connectionContext.DirectInsertAsync(row, "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options: options); @@ -458,6 +550,12 @@ await connectionContext.DirectInsertAsync(compositeKeyRow, Assert.Equal(row.OwnedShippingAddress?.Street, dbRows[0].OwnedShippingAddress?.Street); Assert.Equal(row.OwnedShippingAddress?.Location?.Lat, dbRows[0].OwnedShippingAddress?.Location?.Lat); Assert.Equal(row.OwnedShippingAddress?.Location?.Lng, dbRows[0].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonComplexShippingAddress?.Street, dbRows[0].JsonComplexShippingAddress?.Street); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lat, dbRows[0].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lng, dbRows[0].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonOwnedShippingAddress?.Street, dbRows[0].JsonOwnedShippingAddress?.Street); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lat, dbRows[0].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lng, dbRows[0].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRow.Id1, dbCompositeKeyRows[0].Id1); Assert.Equal(compositeKeyRow.Id2, dbCompositeKeyRows[0].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectInsertTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectInsertTests.cs index ae4ab9d..7e8d2db 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectInsertTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectInsertTests.cs @@ -35,6 +35,24 @@ public void DirectInsert_Using_Linq_Without_Transaction() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street 1", + Location = new OwnedTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street 1", + Location = new ComplexTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street 1", Location = new OwnedTypeLocation @@ -74,7 +92,9 @@ public void DirectInsert_Using_Linq_Without_Transaction() row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: options); @@ -102,6 +122,12 @@ public void DirectInsert_Using_Linq_Without_Transaction() Assert.Equal(row.OwnedShippingAddress?.Street, dbRows[0].OwnedShippingAddress?.Street); Assert.Equal(row.OwnedShippingAddress?.Location?.Lat, dbRows[0].OwnedShippingAddress?.Location?.Lat); Assert.Equal(row.OwnedShippingAddress?.Location?.Lng, dbRows[0].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonComplexShippingAddress?.Street, dbRows[0].JsonComplexShippingAddress?.Street); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lat, dbRows[0].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lng, dbRows[0].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonOwnedShippingAddress?.Street, dbRows[0].JsonOwnedShippingAddress?.Street); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lat, dbRows[0].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lng, dbRows[0].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRow.Id1, dbCompositeKeyRows[0].Id1); Assert.Equal(compositeKeyRow.Id2, dbCompositeKeyRows[0].Id2); @@ -138,6 +164,24 @@ public void DirectInsert_Using_Linq_With_Transaction_Committed() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street 1", + Location = new OwnedTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street 1", + Location = new ComplexTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street 1", Location = new OwnedTypeLocation @@ -172,7 +216,9 @@ public void DirectInsert_Using_Linq_With_Transaction_Committed() row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: new BulkInsertOptions() { @@ -207,6 +253,12 @@ public void DirectInsert_Using_Linq_With_Transaction_Committed() Assert.Equal(row.OwnedShippingAddress?.Street, dbRows[0].OwnedShippingAddress?.Street); Assert.Equal(row.OwnedShippingAddress?.Location?.Lat, dbRows[0].OwnedShippingAddress?.Location?.Lat); Assert.Equal(row.OwnedShippingAddress?.Location?.Lng, dbRows[0].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonComplexShippingAddress?.Street, dbRows[0].JsonComplexShippingAddress?.Street); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lat, dbRows[0].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lng, dbRows[0].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonOwnedShippingAddress?.Street, dbRows[0].JsonOwnedShippingAddress?.Street); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lat, dbRows[0].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lng, dbRows[0].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRow.Id1, dbCompositeKeyRows[0].Id1); Assert.Equal(compositeKeyRow.Id2, dbCompositeKeyRows[0].Id2); @@ -243,6 +295,24 @@ public void DirectInsert_Using_Linq_With_Transaction_RolledBack() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street 1", + Location = new OwnedTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street 1", + Location = new ComplexTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street 1", Location = new OwnedTypeLocation @@ -277,7 +347,9 @@ public void DirectInsert_Using_Linq_With_Transaction_RolledBack() row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: new BulkInsertOptions() { @@ -384,6 +456,24 @@ public void DirectInsert_Using_DynamicString() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street 1", + Location = new OwnedTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street 1", + Location = new ComplexTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street 1", Location = new OwnedTypeLocation @@ -422,7 +512,9 @@ public void DirectInsert_Using_DynamicString() "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options: options); @@ -458,6 +550,12 @@ public void DirectInsert_Using_DynamicString() Assert.Equal(row.OwnedShippingAddress?.Street, dbRows[0].OwnedShippingAddress?.Street); Assert.Equal(row.OwnedShippingAddress?.Location?.Lat, dbRows[0].OwnedShippingAddress?.Location?.Lat); Assert.Equal(row.OwnedShippingAddress?.Location?.Lng, dbRows[0].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonComplexShippingAddress?.Street, dbRows[0].JsonComplexShippingAddress?.Street); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lat, dbRows[0].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lng, dbRows[0].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonOwnedShippingAddress?.Street, dbRows[0].JsonOwnedShippingAddress?.Street); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lat, dbRows[0].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lng, dbRows[0].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRow.Id1, dbCompositeKeyRows[0].Id1); Assert.Equal(compositeKeyRow.Id2, dbCompositeKeyRows[0].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectUpdateAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectUpdateAsyncTests.cs index 679776a..eb0add7 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectUpdateAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectUpdateAsyncTests.cs @@ -40,6 +40,24 @@ private async Task SeedData(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -108,6 +126,24 @@ public async Task DirectUpdate_PrimaryKeys(int index) Lng = -80.0 } }; + row.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + row.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; var compositeKeyRow = compositeKeyRows.Skip(index).First(); compositeKeyRow.Column2 = "abc"; @@ -132,7 +168,9 @@ public async Task DirectUpdate_PrimaryKeys(int index) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: options); @@ -163,6 +201,12 @@ public async Task DirectUpdate_PrimaryKeys(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -213,6 +257,24 @@ public async Task DirectUpdate_PrimaryKeys_DynamicString(int index) Lng = -80.0 } }; + row.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + row.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; var compositeKeyRow = compositeKeyRows.Skip(index).First(); compositeKeyRow.Column2 = "abc"; @@ -236,7 +298,9 @@ public async Task DirectUpdate_PrimaryKeys_DynamicString(int index) "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options: options); @@ -267,6 +331,12 @@ public async Task DirectUpdate_PrimaryKeys_DynamicString(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -317,6 +387,24 @@ public async Task DirectUpdate_SpecifiedKeys(int index) Lng = -80.0 } }; + row.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + row.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; var compositeKeyRow = compositeKeyRows.Skip(index).First(); compositeKeyRow.Column2 = "abc"; @@ -341,7 +429,9 @@ public async Task DirectUpdate_SpecifiedKeys(int index) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: options); @@ -372,6 +462,12 @@ public async Task DirectUpdate_SpecifiedKeys(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -422,6 +518,24 @@ public async Task DirectUpdate_SpecifiedKeys_DynamicString(int index) Lng = -80.0 } }; + row.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + row.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; var compositeKeyRow = compositeKeyRows.Skip(index).First(); compositeKeyRow.Column2 = "abc"; @@ -445,7 +559,9 @@ public async Task DirectUpdate_SpecifiedKeys_DynamicString(int index) "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options: options); @@ -476,6 +592,12 @@ public async Task DirectUpdate_SpecifiedKeys_DynamicString(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectUpdateTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectUpdateTests.cs index 0f85c46..eb355d6 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectUpdateTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/DirectUpdateTests.cs @@ -40,6 +40,24 @@ private void SeedData(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -108,6 +126,24 @@ public void DirectUpdate_PrimaryKeys(int index) Lng = -80.0 } }; + row.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + row.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; var compositeKeyRow = compositeKeyRows.Skip(index).First(); compositeKeyRow.Column2 = "abc"; @@ -132,7 +168,9 @@ public void DirectUpdate_PrimaryKeys(int index) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: options); @@ -163,6 +201,12 @@ public void DirectUpdate_PrimaryKeys(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -213,6 +257,24 @@ public void DirectUpdate_PrimaryKeys_DynamicString(int index) Lng = -80.0 } }; + row.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + row.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; var compositeKeyRow = compositeKeyRows.Skip(index).First(); compositeKeyRow.Column2 = "abc"; @@ -236,7 +298,9 @@ public void DirectUpdate_PrimaryKeys_DynamicString(int index) "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options: options); @@ -267,6 +331,12 @@ public void DirectUpdate_PrimaryKeys_DynamicString(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -317,6 +387,24 @@ public void DirectUpdate_SpecifiedKeys(int index) Lng = -80.0 } }; + row.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + row.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; var compositeKeyRow = compositeKeyRows.Skip(index).First(); compositeKeyRow.Column2 = "abc"; @@ -341,7 +429,9 @@ public void DirectUpdate_SpecifiedKeys(int index) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: options); @@ -372,6 +462,12 @@ public void DirectUpdate_SpecifiedKeys(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -422,6 +518,24 @@ public void DirectUpdate_SpecifiedKeys_DynamicString(int index) Lng = -80.0 } }; + row.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + row.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; var compositeKeyRow = compositeKeyRows.Skip(index).First(); compositeKeyRow.Column2 = "abc"; @@ -445,7 +559,9 @@ public void DirectUpdate_SpecifiedKeys_DynamicString(int index) "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options: options); @@ -476,6 +592,12 @@ public void DirectUpdate_SpecifiedKeys_DynamicString(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/UpsertAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/UpsertAsyncTests.cs index fa34c76..9724348 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/UpsertAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/UpsertAsyncTests.cs @@ -40,6 +40,24 @@ private void SeedData(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -91,6 +109,24 @@ public async Task Upsert_Existing_Using_Linq_With_Transaction(int length) existingRow.Column3 = DateTime.Now; existingRow.Season = Season.Spring; existingRow.SeasonAsString = Season.Spring; + existingRow.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + existingRow.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; var existingCompositeKeyRows = compositeKeyRows.First(); @@ -125,7 +161,9 @@ public async Task Upsert_Existing_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, row => new { @@ -139,7 +177,9 @@ public async Task Upsert_Existing_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: new BulkMergeOptions() { @@ -187,6 +227,12 @@ public async Task Upsert_Existing_Using_Linq_With_Transaction(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -232,6 +278,24 @@ public async Task Upsert_NonExisting_Using_Linq_With_Transaction(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + length, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + length, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + length, Location = new OwnedTypeLocation @@ -278,7 +342,9 @@ public async Task Upsert_NonExisting_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, row => new { @@ -292,7 +358,9 @@ public async Task Upsert_NonExisting_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: new BulkMergeOptions() { @@ -343,6 +411,12 @@ public async Task Upsert_NonExisting_Using_Linq_With_Transaction(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -376,6 +450,24 @@ public async Task Upsert_Existing_Using_Dynamic_String_With_Transaction(int leng existingRow.Column3 = DateTime.Now; existingRow.Season = Season.Spring; existingRow.SeasonAsString = Season.Spring; + existingRow.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + existingRow.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; var existingCompositeKeyRows = compositeKeyRows.First(); @@ -393,14 +485,18 @@ public async Task Upsert_Existing_Using_Dynamic_String_With_Transaction(int leng "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], ["Column1", "Column2", "Column3", "Season", "SeasonAsString", "ComplexShippingAddress.Street", "ComplexShippingAddress.Location.Lat", "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], options: new BulkMergeOptions() { LogTo = LogTo, @@ -447,6 +543,12 @@ public async Task Upsert_Existing_Using_Dynamic_String_With_Transaction(int leng Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -492,6 +594,24 @@ public async Task Upsert_NonExisting_Using_Dynamic_String_With_Transaction(int l } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + length, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + length, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + length, Location = new OwnedTypeLocation @@ -521,14 +641,18 @@ public async Task Upsert_NonExisting_Using_Dynamic_String_With_Transaction(int l "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], ["Column1", "Column2", "Column3", "Season", "SeasonAsString", "ComplexShippingAddress.Street", "ComplexShippingAddress.Location.Lat", "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], options: new BulkMergeOptions() { LogTo = LogTo, @@ -578,6 +702,12 @@ public async Task Upsert_NonExisting_Using_Dynamic_String_With_Transaction(int l Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/UpsertTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/UpsertTests.cs index 8bef698..55fa98a 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/UpsertTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/UpsertTests.cs @@ -40,6 +40,24 @@ private void SeedData(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -91,6 +109,24 @@ public void Upsert_Existing_Using_Linq_With_Transaction(int length) existingRow.Column3 = DateTime.Now; existingRow.Season = Season.Spring; existingRow.SeasonAsString = Season.Spring; + existingRow.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + existingRow.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; var existingCompositeKeyRows = compositeKeyRows.First(); @@ -125,7 +161,9 @@ public void Upsert_Existing_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, row => new { @@ -139,7 +177,9 @@ public void Upsert_Existing_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: new BulkMergeOptions() { @@ -187,6 +227,12 @@ public void Upsert_Existing_Using_Linq_With_Transaction(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -232,6 +278,24 @@ public void Upsert_NonExisting_Using_Linq_With_Transaction(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + length, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + length, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + length, Location = new OwnedTypeLocation @@ -278,7 +342,9 @@ public void Upsert_NonExisting_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, row => new { @@ -292,7 +358,9 @@ public void Upsert_NonExisting_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options: new BulkMergeOptions() { @@ -343,6 +411,12 @@ public void Upsert_NonExisting_Using_Linq_With_Transaction(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -376,7 +450,24 @@ public void Upsert_Existing_Using_Dynamic_String_With_Transaction(int length) existingRow.Column3 = DateTime.Now; existingRow.Season = Season.Spring; existingRow.SeasonAsString = Season.Spring; - + existingRow.JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Updated Street", + Location = new ComplexTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; + existingRow.JsonOwnedShippingAddress = new JsonOwnedTypeAddress + { + Street = "Updated Street", + Location = new OwnedTypeLocation + { + Lat = 50.0, + Lng = -80.0 + } + }; var existingCompositeKeyRows = compositeKeyRows.First(); @@ -393,14 +484,18 @@ public void Upsert_Existing_Using_Dynamic_String_With_Transaction(int length) "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], ["Column1", "Column2", "Column3", "Season", "SeasonAsString", "ComplexShippingAddress.Street", "ComplexShippingAddress.Location.Lat", "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], options: new BulkMergeOptions() { LogTo = LogTo, @@ -447,6 +542,12 @@ public void Upsert_Existing_Using_Dynamic_String_With_Transaction(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -492,6 +593,24 @@ public void Upsert_NonExisting_Using_Dynamic_String_With_Transaction(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + length, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + length, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + length, Location = new OwnedTypeLocation @@ -521,14 +640,18 @@ public void Upsert_NonExisting_Using_Dynamic_String_With_Transaction(int length) "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], ["Column1", "Column2", "Column3", "Season", "SeasonAsString", "ComplexShippingAddress.Street", "ComplexShippingAddress.Location.Lat", "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], options: new BulkMergeOptions() { LogTo = LogTo, @@ -578,6 +701,12 @@ public void Upsert_NonExisting_Using_Dynamic_String_With_Transaction(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/ComplexTypes.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/ComplexTypes.cs index e9fc715..ca59eb8 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/ComplexTypes.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/ComplexTypes.cs @@ -17,3 +17,10 @@ public class ComplexTypeLocation public double Lng { get; set; } } + +public class JsonComplexTypeAddress +{ + public string Street { get; set; } + + public ComplexTypeLocation Location { get; set; } +} diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/OwnedTypes.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/OwnedTypes.cs index 53cfa86..167724b 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/OwnedTypes.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/OwnedTypes.cs @@ -17,3 +17,10 @@ public class OwnedTypeLocation public double Lng { get; set; } } + +public class JsonOwnedTypeAddress +{ + public string Street { get; set; } + + public OwnedTypeLocation Location { get; set; } +} \ No newline at end of file diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/SingleKeyRow.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/SingleKeyRow.cs index 232f1b5..7285014 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/SingleKeyRow.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/SingleKeyRow.cs @@ -39,6 +39,10 @@ public class SingleKeyRow public ComplexTypeAddress ComplexShippingAddress { get; set; } public OwnedTypeAddress OwnedShippingAddress { get; set; } + + public JsonComplexTypeAddress JsonComplexShippingAddress { get; set; } + + public JsonOwnedTypeAddress JsonOwnedShippingAddress { get; set; } } public class ExtendedSingleKeyRow : SingleKeyRow diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/TestDbContext.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/TestDbContext.cs index b90acd5..3e8733b 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/TestDbContext.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/Database/TestDbContext.cs @@ -32,7 +32,6 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder) { - if (!string.IsNullOrEmpty(_schema)) { modelBuilder.HasDefaultSchema(_schema); @@ -40,10 +39,25 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity>().Property(x => x.SeasonAsString).HasConversion(v => v.ToString(), v => (Season)Enum.Parse(typeof(Season), v)); + modelBuilder.Entity>().ComplexProperty(x => x.JsonComplexShippingAddress, x => + { + if (!_enableDiscriminator) + { + x.ToJson(); + } + }); + + modelBuilder.Entity>().OwnsOne(x => x.JsonOwnedShippingAddress, x => + { + x.ToJson(); + }); + modelBuilder.Entity>().HasKey(x => new { x.Id1, x.Id2 }); modelBuilder.Entity>().Property(x => x.SeasonAsString).HasConversion(v => v.ToString(), v => (Season)Enum.Parse(typeof(Season), v)); modelBuilder.Entity().Property(x => x.Id).HasDefaultValueSql("newsequentialid()"); + modelBuilder.Entity().Property(x => x.Id).HasColumnName("Id1"); + modelBuilder.Entity().Property(x => x.Key).HasColumnName("Key1"); modelBuilder.Entity().Property(x => x.Id).HasDefaultValueSql("newsequentialid()"); modelBuilder.Entity().Property(x => x.SeasonAsString).HasConversion(v => v.ToString(), v => (Season)Enum.Parse(typeof(Season), v)); @@ -51,6 +65,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity().Property(x => x.Id).HasDefaultValueSql("newsequentialid()"); modelBuilder.Entity().Property(x => x.SeasonAsString).HasConversion(v => v.ToString(), v => (Season)Enum.Parse(typeof(Season), v)); + if (_enableDiscriminator) { modelBuilder.Entity>(); @@ -60,4 +75,4 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) base.OnModelCreating(modelBuilder); } -} +} \ No newline at end of file diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/ComplexTypes.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/ComplexTypes.cs index 5941d5f..041b82d 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/ComplexTypes.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/ComplexTypes.cs @@ -17,3 +17,10 @@ public class ComplexTypeLocation public double Lng { get; set; } } + +public class JsonComplexTypeAddress +{ + public string Street { get; set; } + + public ComplexTypeLocation Location { get; set; } +} diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/OwnedTypes.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/OwnedTypes.cs index 45ca62a..75e10ea 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/OwnedTypes.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/OwnedTypes.cs @@ -17,3 +17,10 @@ public class OwnedTypeLocation public double Lng { get; set; } } + +public class JsonOwnedTypeAddress +{ + public string Street { get; set; } + + public OwnedTypeLocation Location { get; set; } +} \ No newline at end of file diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/SingleKeyRow.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/SingleKeyRow.cs index 6a3e5d9..76b5e86 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/SingleKeyRow.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/SingleKeyRow.cs @@ -39,6 +39,10 @@ public class SingleKeyRow public ComplexTypeAddress ComplexShippingAddress { get; set; } public OwnedTypeAddress OwnedShippingAddress { get; set; } + + public JsonComplexTypeAddress JsonComplexShippingAddress { get; set; } + + public JsonOwnedTypeAddress JsonOwnedShippingAddress { get; set; } } public class ExtendedSingleKeyRow : SingleKeyRow diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/TestDbContext.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/TestDbContext.cs index ae943c3..07b83b1 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/TestDbContext.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/Database/TestDbContext.cs @@ -39,6 +39,19 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity>().Property(x => x.SeasonAsString).HasConversion(v => v.ToString(), v => (Season)Enum.Parse(typeof(Season), v)); + modelBuilder.Entity>().ComplexProperty(x => x.JsonComplexShippingAddress, x => + { + if (!_enableDiscriminator) + { + x.ToJson(); + } + }); + + modelBuilder.Entity>().OwnsOne(x => x.JsonOwnedShippingAddress, x => + { + x.ToJson(); + }); + modelBuilder.Entity>().HasKey(x => new { x.Id1, x.Id2 }); modelBuilder.Entity>().Property(x => x.SeasonAsString).HasConversion(v => v.ToString(), v => (Season)Enum.Parse(typeof(Season), v)); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkDeleteAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkDeleteAsyncTests.cs index 15ef9a5..100144b 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkDeleteAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkDeleteAsyncTests.cs @@ -35,6 +35,24 @@ public BulkDeleteAsyncTests(ITestOutputHelper output, SqlServerFixture fixture) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkDeleteTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkDeleteTests.cs index 9bf31a4..9688809 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkDeleteTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkDeleteTests.cs @@ -35,6 +35,24 @@ public BulkDeleteTests(ITestOutputHelper output, SqlServerFixture fixture) : bas } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkInsertAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkInsertAsyncTests.cs index 358a013..457897d 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkInsertAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkInsertAsyncTests.cs @@ -39,6 +39,24 @@ public async Task BulkInsert_Using_Linq_Without_Transaction(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -79,7 +97,9 @@ await _context.BulkInsertAsync(rows, row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options); @@ -106,6 +126,12 @@ await _context.BulkInsertAsync(compositeKeyRows, Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -146,6 +172,24 @@ public async Task BulkInsert_Using_Linq_With_Transaction_Committed(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -181,7 +225,9 @@ await _context.BulkInsertAsync(rows, row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }); await _context.BulkInsertAsync(compositeKeyRows, @@ -207,6 +253,12 @@ await _context.BulkInsertAsync(compositeKeyRows, Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -247,6 +299,24 @@ public async Task BulkInsert_Using_Linq_With_Transaction_RolledBack(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -282,7 +352,9 @@ await _context.BulkInsertAsync(rows, row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }); await _context.BulkInsertAsync(compositeKeyRows, @@ -404,6 +476,24 @@ public async Task BulkInsert_Using_DynamicString(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -443,7 +533,9 @@ await _context.BulkInsertAsync(rows, "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options); @@ -478,6 +570,12 @@ await _context.BulkInsertAsync(compositeKeyRows, Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkInsertTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkInsertTests.cs index 9c65b5c..6fdc90a 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkInsertTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkInsertTests.cs @@ -39,6 +39,24 @@ public void BulkInsert_Using_Linq_Without_Transaction(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -79,7 +97,9 @@ public void BulkInsert_Using_Linq_Without_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options); @@ -106,6 +126,12 @@ public void BulkInsert_Using_Linq_Without_Transaction(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -146,6 +172,24 @@ public void BulkInsert_Using_Linq_With_Transaction_Committed(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -181,7 +225,9 @@ public void BulkInsert_Using_Linq_With_Transaction_Committed(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }); _context.BulkInsert(compositeKeyRows, @@ -207,6 +253,12 @@ public void BulkInsert_Using_Linq_With_Transaction_Committed(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -247,6 +299,24 @@ public void BulkInsert_Using_Linq_With_Transaction_RolledBack(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -282,7 +352,9 @@ public void BulkInsert_Using_Linq_With_Transaction_RolledBack(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }); _context.BulkInsert(compositeKeyRows, @@ -404,6 +476,24 @@ public void BulkInsert_Using_DynamicString(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -443,7 +533,9 @@ public void BulkInsert_Using_DynamicString(int length) "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options); @@ -478,6 +570,12 @@ public void BulkInsert_Using_DynamicString(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkMergeAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkMergeAsyncTests.cs index 3a829fb..73eb69c 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkMergeAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkMergeAsyncTests.cs @@ -39,6 +39,24 @@ private async Task SeedData(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -117,6 +135,24 @@ public async Task BulkMerge_Using_Linq_With_Transaction(int length, int insertLe } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -153,7 +189,9 @@ public async Task BulkMerge_Using_Linq_With_Transaction(int length, int insertLe row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, row => new { @@ -167,7 +205,9 @@ public async Task BulkMerge_Using_Linq_With_Transaction(int length, int insertLe row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, new BulkMergeOptions() { @@ -212,6 +252,12 @@ public async Task BulkMerge_Using_Linq_With_Transaction(int length, int insertLe Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -272,6 +318,24 @@ public async Task BulkMerge_Using_Dynamic_String_With_Transaction(int length, in } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -302,14 +366,18 @@ public async Task BulkMerge_Using_Dynamic_String_With_Transaction(int length, in "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], ["Column1", "Column2", "Column3", "Season", "SeasonAsString", "ComplexShippingAddress.Street", "ComplexShippingAddress.Location.Lat", "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], new BulkMergeOptions() { LogTo = LogTo, @@ -352,6 +420,12 @@ public async Task BulkMerge_Using_Dynamic_String_With_Transaction(int length, in Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkMergeTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkMergeTests.cs index 26e57ea..97749e2 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkMergeTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkMergeTests.cs @@ -39,6 +39,24 @@ private void SeedData(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -117,6 +135,24 @@ public void BulkMerge_Using_Linq_With_Transaction(int length, int insertLength) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -153,7 +189,9 @@ public void BulkMerge_Using_Linq_With_Transaction(int length, int insertLength) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, row => new { @@ -167,7 +205,9 @@ public void BulkMerge_Using_Linq_With_Transaction(int length, int insertLength) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, new BulkMergeOptions() { @@ -212,6 +252,12 @@ public void BulkMerge_Using_Linq_With_Transaction(int length, int insertLength) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -272,6 +318,24 @@ public void BulkMerge_Using_Dynamic_String_With_Transaction(int length, int inse } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -302,14 +366,18 @@ public void BulkMerge_Using_Dynamic_String_With_Transaction(int length, int inse "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], ["Column1", "Column2", "Column3", "Season", "SeasonAsString", "ComplexShippingAddress.Street", "ComplexShippingAddress.Location.Lat", "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], new BulkMergeOptions() { LogTo = LogTo, @@ -352,6 +420,12 @@ public void BulkMerge_Using_Dynamic_String_With_Transaction(int length, int inse Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkUpdateAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkUpdateAsyncTests.cs index 187dacd..b4f0d22 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkUpdateAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkUpdateAsyncTests.cs @@ -39,6 +39,24 @@ private async Task SeedData(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -132,6 +150,12 @@ public async Task BulkUpdate_PrimaryKeys(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -207,6 +231,12 @@ public async Task BulkUpdate_PrimaryKeys_DynamicString(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -282,6 +312,12 @@ public async Task BulkUpdate_SpecifiedKeys(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -357,6 +393,12 @@ public async Task BulkUpdate_SpecifiedKeys_DynamicString(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkUpdateTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkUpdateTests.cs index 37dd614..5a05a2b 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkUpdateTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/BulkUpdateTests.cs @@ -39,6 +39,24 @@ private void SeedData(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -132,6 +150,12 @@ public void BulkUpdate_PrimaryKeys(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -207,6 +231,12 @@ public void BulkUpdate_PrimaryKeys_DynamicString(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -282,6 +312,12 @@ public void BulkUpdate_SpecifiedKeys(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -357,6 +393,12 @@ public void BulkUpdate_SpecifiedKeys_DynamicString(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectDeleteAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectDeleteAsyncTests.cs index 4107472..f033b2f 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectDeleteAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectDeleteAsyncTests.cs @@ -36,6 +36,24 @@ public DirectDeleteAsyncTests(ITestOutputHelper output, SqlServerFixture fixture } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectDeleteTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectDeleteTests.cs index 5558439..1c5b22f 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectDeleteTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectDeleteTests.cs @@ -36,6 +36,24 @@ public DirectDeleteTests(ITestOutputHelper output, SqlServerFixture fixture) : b } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectInsertAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectInsertAsyncTests.cs index a7e88a2..a85c54d 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectInsertAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectInsertAsyncTests.cs @@ -33,6 +33,24 @@ public async Task DirectInsert_Using_Linq_Without_Transaction() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + 1, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + 1, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + 1, Location = new OwnedTypeLocation @@ -72,7 +90,9 @@ await _context.DirectInsertAsync(row, row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options); @@ -100,6 +120,12 @@ await _context.DirectInsertAsync(compositeKeyRow, Assert.Equal(row.OwnedShippingAddress?.Street, dbRows[0].OwnedShippingAddress?.Street); Assert.Equal(row.OwnedShippingAddress?.Location?.Lat, dbRows[0].OwnedShippingAddress?.Location?.Lat); Assert.Equal(row.OwnedShippingAddress?.Location?.Lng, dbRows[0].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonComplexShippingAddress?.Street, dbRows[0].JsonComplexShippingAddress?.Street); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lat, dbRows[0].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lng, dbRows[0].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonOwnedShippingAddress?.Street, dbRows[0].JsonOwnedShippingAddress?.Street); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lat, dbRows[0].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lng, dbRows[0].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRow.Id1, dbCompositeKeyRows[0].Id1); Assert.Equal(compositeKeyRow.Id2, dbCompositeKeyRows[0].Id2); @@ -132,6 +158,24 @@ public async Task DirectInsert_Using_Linq_With_Transaction_Committed() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + 1, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + 1, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + 1, Location = new OwnedTypeLocation @@ -166,7 +210,9 @@ await _context.DirectInsertAsync(row, row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, new BulkInsertOptions() { @@ -201,6 +247,12 @@ await _context.DirectInsertAsync(compositeKeyRow, Assert.Equal(row.OwnedShippingAddress?.Street, dbRows[0].OwnedShippingAddress?.Street); Assert.Equal(row.OwnedShippingAddress?.Location?.Lat, dbRows[0].OwnedShippingAddress?.Location?.Lat); Assert.Equal(row.OwnedShippingAddress?.Location?.Lng, dbRows[0].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonComplexShippingAddress?.Street, dbRows[0].JsonComplexShippingAddress?.Street); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lat, dbRows[0].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lng, dbRows[0].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonOwnedShippingAddress?.Street, dbRows[0].JsonOwnedShippingAddress?.Street); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lat, dbRows[0].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lng, dbRows[0].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRow.Id1, dbCompositeKeyRows[0].Id1); Assert.Equal(compositeKeyRow.Id2, dbCompositeKeyRows[0].Id2); @@ -233,6 +285,24 @@ public async Task DirectInsert_Using_Linq_With_Transaction_RolledBack() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + 1, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + 1, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + 1, Location = new OwnedTypeLocation @@ -267,7 +337,9 @@ await _context.DirectInsertAsync(row, row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, new BulkInsertOptions() { @@ -368,6 +440,24 @@ public async Task DirectInsert_Using_DynamicString() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + 1, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + 1, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + 1, Location = new OwnedTypeLocation @@ -406,7 +496,9 @@ await _context.DirectInsertAsync(row, "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options); @@ -442,6 +534,12 @@ await _context.DirectInsertAsync(compositeKeyRow, Assert.Equal(row.OwnedShippingAddress?.Street, dbRows[0].OwnedShippingAddress?.Street); Assert.Equal(row.OwnedShippingAddress?.Location?.Lat, dbRows[0].OwnedShippingAddress?.Location?.Lat); Assert.Equal(row.OwnedShippingAddress?.Location?.Lng, dbRows[0].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonComplexShippingAddress?.Street, dbRows[0].JsonComplexShippingAddress?.Street); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lat, dbRows[0].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lng, dbRows[0].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonOwnedShippingAddress?.Street, dbRows[0].JsonOwnedShippingAddress?.Street); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lat, dbRows[0].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lng, dbRows[0].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRow.Id1, dbCompositeKeyRows[0].Id1); Assert.Equal(compositeKeyRow.Id2, dbCompositeKeyRows[0].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectInsertTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectInsertTests.cs index e41aa0a..e6f5bd8 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectInsertTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectInsertTests.cs @@ -33,6 +33,24 @@ public void DirectInsert_Using_Linq_Without_Transaction() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + 1, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + 1, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + 1, Location = new OwnedTypeLocation @@ -72,7 +90,9 @@ public void DirectInsert_Using_Linq_Without_Transaction() row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, options); @@ -100,6 +120,12 @@ public void DirectInsert_Using_Linq_Without_Transaction() Assert.Equal(row.OwnedShippingAddress?.Street, dbRows[0].OwnedShippingAddress?.Street); Assert.Equal(row.OwnedShippingAddress?.Location?.Lat, dbRows[0].OwnedShippingAddress?.Location?.Lat); Assert.Equal(row.OwnedShippingAddress?.Location?.Lng, dbRows[0].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonComplexShippingAddress?.Street, dbRows[0].JsonComplexShippingAddress?.Street); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lat, dbRows[0].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lng, dbRows[0].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonOwnedShippingAddress?.Street, dbRows[0].JsonOwnedShippingAddress?.Street); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lat, dbRows[0].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lng, dbRows[0].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRow.Id1, dbCompositeKeyRows[0].Id1); Assert.Equal(compositeKeyRow.Id2, dbCompositeKeyRows[0].Id2); @@ -132,6 +158,24 @@ public void DirectInsert_Using_Linq_With_Transaction_Committed() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + 1, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + 1, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + 1, Location = new OwnedTypeLocation @@ -166,7 +210,9 @@ public void DirectInsert_Using_Linq_With_Transaction_Committed() row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, new BulkInsertOptions() { @@ -174,11 +220,11 @@ public void DirectInsert_Using_Linq_With_Transaction_Committed() }); _context.DirectInsert(compositeKeyRow, - row => new { row.Id1, row.Id2, row.Column1, row.Column2, row.Column3, row.Season, row.SeasonAsString }, - new BulkInsertOptions() - { - LogTo = LogTo - }); + row => new { row.Id1, row.Id2, row.Column1, row.Column2, row.Column3, row.Season, row.SeasonAsString }, + new BulkInsertOptions() + { + LogTo = LogTo + }); tran.Commit(); @@ -201,6 +247,12 @@ public void DirectInsert_Using_Linq_With_Transaction_Committed() Assert.Equal(row.OwnedShippingAddress?.Street, dbRows[0].OwnedShippingAddress?.Street); Assert.Equal(row.OwnedShippingAddress?.Location?.Lat, dbRows[0].OwnedShippingAddress?.Location?.Lat); Assert.Equal(row.OwnedShippingAddress?.Location?.Lng, dbRows[0].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonComplexShippingAddress?.Street, dbRows[0].JsonComplexShippingAddress?.Street); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lat, dbRows[0].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lng, dbRows[0].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonOwnedShippingAddress?.Street, dbRows[0].JsonOwnedShippingAddress?.Street); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lat, dbRows[0].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lng, dbRows[0].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRow.Id1, dbCompositeKeyRows[0].Id1); Assert.Equal(compositeKeyRow.Id2, dbCompositeKeyRows[0].Id2); @@ -233,6 +285,24 @@ public void DirectInsert_Using_Linq_With_Transaction_RolledBack() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + 1, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + 1, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + 1, Location = new OwnedTypeLocation @@ -267,12 +337,14 @@ public void DirectInsert_Using_Linq_With_Transaction_RolledBack() row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, - new BulkInsertOptions() - { - LogTo = LogTo - }); + new BulkInsertOptions() + { + LogTo = LogTo + }); _context.DirectInsert(compositeKeyRow, row => new { row.Id1, row.Id2, row.Column1, row.Column2, row.Column3, row.Season, row.SeasonAsString }, @@ -368,6 +440,24 @@ public void DirectInsert_Using_DynamicString() } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + 1, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + 1, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + 1, + Lng = -74.0060 - 1 + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + 1, Location = new OwnedTypeLocation @@ -406,7 +496,9 @@ public void DirectInsert_Using_DynamicString() "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng" + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress" ], options); @@ -442,6 +534,12 @@ public void DirectInsert_Using_DynamicString() Assert.Equal(row.OwnedShippingAddress?.Street, dbRows[0].OwnedShippingAddress?.Street); Assert.Equal(row.OwnedShippingAddress?.Location?.Lat, dbRows[0].OwnedShippingAddress?.Location?.Lat); Assert.Equal(row.OwnedShippingAddress?.Location?.Lng, dbRows[0].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonComplexShippingAddress?.Street, dbRows[0].JsonComplexShippingAddress?.Street); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lat, dbRows[0].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonComplexShippingAddress?.Location?.Lng, dbRows[0].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(row.JsonOwnedShippingAddress?.Street, dbRows[0].JsonOwnedShippingAddress?.Street); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lat, dbRows[0].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(row.JsonOwnedShippingAddress?.Location?.Lng, dbRows[0].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRow.Id1, dbCompositeKeyRows[0].Id1); Assert.Equal(compositeKeyRow.Id2, dbCompositeKeyRows[0].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectUpdateAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectUpdateAsyncTests.cs index 4597128..3ce9ba0 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectUpdateAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectUpdateAsyncTests.cs @@ -40,6 +40,24 @@ private async Task SeedData(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -129,6 +147,12 @@ public async Task DirectUpdate_PrimaryKeys(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -200,6 +224,12 @@ public async Task DirectUpdate_PrimaryKeys_DynamicString(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -271,6 +301,12 @@ public async Task DirectUpdate_SpecifiedKeys(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -342,6 +378,12 @@ public async Task DirectUpdate_SpecifiedKeys_DynamicString(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectUpdateTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectUpdateTests.cs index 4d50900..c671a40 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectUpdateTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/DirectUpdateTests.cs @@ -40,6 +40,24 @@ private void SeedData(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -129,6 +147,12 @@ public void DirectUpdate_PrimaryKeys(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -200,6 +224,12 @@ public void DirectUpdate_PrimaryKeys_DynamicString(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -271,6 +301,12 @@ public void DirectUpdate_SpecifiedKeys(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -342,6 +378,12 @@ public void DirectUpdate_SpecifiedKeys_DynamicString(int index) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/UpsertAsyncTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/UpsertAsyncTests.cs index 72fbe37..99d25a4 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/UpsertAsyncTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/UpsertAsyncTests.cs @@ -40,6 +40,24 @@ private void SeedData(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -121,7 +139,9 @@ public async Task Upsert_Existing_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, row => new { @@ -135,7 +155,9 @@ public async Task Upsert_Existing_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, new BulkMergeOptions() { @@ -183,6 +205,12 @@ public async Task Upsert_Existing_Using_Linq_With_Transaction(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -224,6 +252,24 @@ public async Task Upsert_NonExisting_Using_Linq_With_Transaction(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + length, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + length, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + length, Location = new OwnedTypeLocation @@ -270,7 +316,9 @@ public async Task Upsert_NonExisting_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, row => new { @@ -284,13 +332,15 @@ public async Task Upsert_NonExisting_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, - new BulkMergeOptions() - { - LogTo = LogTo, - ReturnDbGeneratedId = true - }); + new BulkMergeOptions() + { + LogTo = LogTo, + ReturnDbGeneratedId = true + }); var result2 = await _context.UpsertAsync(newCompositeKeyRow, row => new { row.Id1, row.Id2 }, @@ -335,6 +385,12 @@ public async Task Upsert_NonExisting_Using_Linq_With_Transaction(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -381,14 +437,18 @@ public async Task Upsert_Existing_Using_Dynamic_String_With_Transaction(int leng "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], ["Column1", "Column2", "Column3", "Season", "SeasonAsString", "ComplexShippingAddress.Street", "ComplexShippingAddress.Location.Lat", "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], new BulkMergeOptions() { LogTo = LogTo, @@ -396,8 +456,8 @@ public async Task Upsert_Existing_Using_Dynamic_String_With_Transaction(int leng }); var result2 = await _context.UpsertAsync(existingCompositeKeyRows, - ["Id1", "Id2"], - ["Column1", "Column2", "Column3", "Season", "SeasonAsString"], + ["Id1", "Id2"], + ["Column1", "Column2", "Column3", "Season", "SeasonAsString"], ["Id1", "Id2", "Column1", "Column2", "Column3", "Season", "SeasonAsString"], new BulkMergeOptions() { @@ -435,6 +495,12 @@ public async Task Upsert_Existing_Using_Dynamic_String_With_Transaction(int leng Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -476,6 +542,24 @@ public async Task Upsert_NonExisting_Using_Dynamic_String_With_Transaction(int l } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + length, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + length, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + length, Location = new OwnedTypeLocation @@ -505,14 +589,18 @@ public async Task Upsert_NonExisting_Using_Dynamic_String_With_Transaction(int l "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], ["Column1", "Column2", "Column3", "Season", "SeasonAsString", "ComplexShippingAddress.Street", "ComplexShippingAddress.Location.Lat", "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], new BulkMergeOptions() { LogTo = LogTo, @@ -523,10 +611,10 @@ public async Task Upsert_NonExisting_Using_Dynamic_String_With_Transaction(int l ["Id1", "Id2"], ["Column1", "Column2", "Column3", "Season", "SeasonAsString"], ["Id1", "Id2", "Column1", "Column2", "Column3", "Season", "SeasonAsString"], - new BulkMergeOptions() - { - LogTo = LogTo - }); + new BulkMergeOptions() + { + LogTo = LogTo + }); tran.Commit(); @@ -562,6 +650,12 @@ public async Task Upsert_NonExisting_Using_Dynamic_String_With_Transaction(int l Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/UpsertTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/UpsertTests.cs index 1129ff2..aa837c5 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/UpsertTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.DbContextExtensionsTests/DbContextExtensions/UpsertTests.cs @@ -40,6 +40,24 @@ private void SeedData(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + i, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + i, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + i, + Lng = -74.0060 - i + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + i, Location = new OwnedTypeLocation @@ -121,7 +139,9 @@ public void Upsert_Existing_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, row => new { @@ -135,7 +155,9 @@ public void Upsert_Existing_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, new BulkMergeOptions() { @@ -183,6 +205,12 @@ public void Upsert_Existing_Using_Linq_With_Transaction(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -224,6 +252,24 @@ public void Upsert_NonExisting_Using_Linq_With_Transaction(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + length, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + length, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + length, Location = new OwnedTypeLocation @@ -270,7 +316,9 @@ public void Upsert_NonExisting_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, row => new { @@ -284,7 +332,9 @@ public void Upsert_NonExisting_Using_Linq_With_Transaction(int length) row.ComplexShippingAddress.Location.Lng, a = row.OwnedShippingAddress.Street, b = row.OwnedShippingAddress.Location.Lat, - c = row.OwnedShippingAddress.Location.Lng + c = row.OwnedShippingAddress.Location.Lng, + row.JsonComplexShippingAddress, + row.JsonOwnedShippingAddress }, new BulkMergeOptions() { @@ -335,6 +385,12 @@ public void Upsert_NonExisting_Using_Linq_With_Transaction(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -381,14 +437,18 @@ public void Upsert_Existing_Using_Dynamic_String_With_Transaction(int length) "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], ["Column1", "Column2", "Column3", "Season", "SeasonAsString", "ComplexShippingAddress.Street", "ComplexShippingAddress.Location.Lat", "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], new BulkMergeOptions() { LogTo = LogTo, @@ -435,6 +495,12 @@ public void Upsert_Existing_Using_Dynamic_String_With_Transaction(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); @@ -476,6 +542,24 @@ public void Upsert_NonExisting_Using_Dynamic_String_With_Transaction(int length) } }, OwnedShippingAddress = new OwnedTypeAddress + { + Street = "Street " + length, + Location = new OwnedTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonComplexShippingAddress = new JsonComplexTypeAddress + { + Street = "Street " + length, + Location = new ComplexTypeLocation + { + Lat = 40.7128 + length, + Lng = -74.0060 - length + } + }, + JsonOwnedShippingAddress = new JsonOwnedTypeAddress { Street = "Street " + length, Location = new OwnedTypeLocation @@ -505,14 +589,18 @@ public void Upsert_NonExisting_Using_Dynamic_String_With_Transaction(int length) "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], ["Column1", "Column2", "Column3", "Season", "SeasonAsString", "ComplexShippingAddress.Street", "ComplexShippingAddress.Location.Lat", "ComplexShippingAddress.Location.Lng", "OwnedShippingAddress.Street", "OwnedShippingAddress.Location.Lat", - "OwnedShippingAddress.Location.Lng"], + "OwnedShippingAddress.Location.Lng", + "JsonComplexShippingAddress", + "JsonOwnedShippingAddress"], new BulkMergeOptions() { LogTo = LogTo, @@ -562,6 +650,12 @@ public void Upsert_NonExisting_Using_Dynamic_String_With_Transaction(int length) Assert.Equal(rows[i].OwnedShippingAddress?.Street, dbRows[i].OwnedShippingAddress?.Street); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lat, dbRows[i].OwnedShippingAddress?.Location?.Lat); Assert.Equal(rows[i].OwnedShippingAddress?.Location?.Lng, dbRows[i].OwnedShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Street, dbRows[i].JsonComplexShippingAddress?.Street); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lat, dbRows[i].JsonComplexShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonComplexShippingAddress?.Location?.Lng, dbRows[i].JsonComplexShippingAddress?.Location?.Lng); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Street, dbRows[i].JsonOwnedShippingAddress?.Street); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lat, dbRows[i].JsonOwnedShippingAddress?.Location?.Lat); + Assert.Equal(rows[i].JsonOwnedShippingAddress?.Location?.Lng, dbRows[i].JsonOwnedShippingAddress?.Location?.Lng); Assert.Equal(compositeKeyRows[i].Id1, dbCompositeKeyRows[i].Id1); Assert.Equal(compositeKeyRows[i].Id2, dbCompositeKeyRows[i].Id2); diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/ComplexOwnedTypeOrder.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/ComplexOwnedTypeOrder.cs index 4764a47..710b4ae 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/ComplexOwnedTypeOrder.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/ComplexOwnedTypeOrder.cs @@ -6,5 +6,14 @@ public class ComplexOwnedTypeOrder public ComplexTypeAddress ComplexShippingAddress { get; set; } + public OwnedTypeAddress OwnedShippingAddress { get; set; } +} + +public class JsonComplexOwnedTypeOrder +{ + public int Id { get; set; } + + public ComplexTypeAddress ComplexShippingAddress { get; set; } + public OwnedTypeAddress OwnedShippingAddress { get; set; } } \ No newline at end of file diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/ComplexTypeOrder.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/ComplexTypeOrder.cs index 05a7612..87e7783 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/ComplexTypeOrder.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/ComplexTypeOrder.cs @@ -23,4 +23,11 @@ public class ComplexTypeLocation public double Lat { get; set; } public double Lng { get; set; } +} + +public class JsonComplexTypeOrder +{ + public int Id { get; set; } + + public ComplexTypeAddress ShippingAddress { get; set; } } \ No newline at end of file diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/OwnedTypeOrder.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/OwnedTypeOrder.cs index 8da63b7..fae2759 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/OwnedTypeOrder.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/OwnedTypeOrder.cs @@ -23,4 +23,11 @@ public class OwnedTypeLocation public double Lat { get; set; } public double Lng { get; set; } +} + +public class JsonOwnedTypeOrder +{ + public int Id { get; set; } + + public OwnedTypeAddress ShippingAddress { get; set; } } \ No newline at end of file diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/TestDbContext.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/TestDbContext.cs index 735436e..6f53e02 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/TestDbContext.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/Database/TestDbContext.cs @@ -21,6 +21,12 @@ public class TestDbContext : DbContext public DbSet ComplexOwnedTypeOrders { get; set; } + public DbSet JsonComplexTypeOrders { get; set; } + + public DbSet JsonOwnedTypeOrders { get; set; } + + public DbSet JsonComplexOwnedTypeOrders { get; set; } + public DbSet Blogs { get; set; } public DbSet RssBlogs { get; set; } @@ -41,7 +47,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder) { - if(!string.IsNullOrEmpty(_schema)) + if (!string.IsNullOrEmpty(_schema)) { modelBuilder.HasDefaultSchema(_schema); } @@ -59,6 +65,46 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity().Property(x => x.Id).HasDefaultValueSql("newsequentialid()"); + modelBuilder.Entity().ComplexProperty(x => x.ShippingAddress, x => + { + x.ToJson(); + //x.ToJson("xxx").HasColumnType("json"); + x.ComplexProperty(y => y.Location, y => + { + y.HasJsonPropertyName("xxx"); + }); + }); + + modelBuilder.Entity().OwnsOne(x => x.ShippingAddress, x => + { + x.ToJson(); + //x.ToJson("xxx").HasColumnType("json"); + x.OwnsOne(y => y.Location, y => + { + y.HasJsonPropertyName("xxx"); + }); + }); + + modelBuilder.Entity().ComplexProperty(x => x.ComplexShippingAddress, x => + { + x.ToJson(); + //x.ToJson("xxx").HasColumnType("json"); + x.ComplexProperty(y => y.Location, y => + { + y.HasJsonPropertyName("xxx"); + }); + }); + + modelBuilder.Entity().OwnsOne(x => x.OwnedShippingAddress, x => + { + x.ToJson(); + //x.ToJson("xxx").HasColumnType("json"); + x.OwnsOne(y => y.Location, y => + { + y.HasJsonPropertyName("xxx"); + }); + }); + base.OnModelCreating(modelBuilder); } } diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions/GetPropertiesTests.GetProperties_JsonComplexOwnedType_ReturnsCorrectColumnInformation.verified.txt b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions/GetPropertiesTests.GetProperties_JsonComplexOwnedType_ReturnsCorrectColumnInformation.verified.txt new file mode 100644 index 0000000..53b9520 --- /dev/null +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions/GetPropertiesTests.GetProperties_JsonComplexOwnedType_ReturnsCorrectColumnInformation.verified.txt @@ -0,0 +1,14 @@ +{ + "Street": "123 Main St", + "xxx": { + "Lat": 40.7128, + "Lng": -74.006 + } +} +{ + "Street": "123 Main St", + "xxx": { + "Lat": 40.7128, + "Lng": -74.006 + } +} \ No newline at end of file diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions/GetPropertiesTests.GetProperties_JsonComplexType_ReturnsCorrectColumnInformation.verified.txt b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions/GetPropertiesTests.GetProperties_JsonComplexType_ReturnsCorrectColumnInformation.verified.txt new file mode 100644 index 0000000..ee99c20 --- /dev/null +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions/GetPropertiesTests.GetProperties_JsonComplexType_ReturnsCorrectColumnInformation.verified.txt @@ -0,0 +1,7 @@ +{ + "Street": "123 Main St", + "xxx": { + "Lat": 40.7128, + "Lng": -74.006 + } +} \ No newline at end of file diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions/GetPropertiesTests.GetProperties_JsonOwnedType_ReturnsCorrectColumnInformation.verified.txt b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions/GetPropertiesTests.GetProperties_JsonOwnedType_ReturnsCorrectColumnInformation.verified.txt new file mode 100644 index 0000000..ee99c20 --- /dev/null +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions/GetPropertiesTests.GetProperties_JsonOwnedType_ReturnsCorrectColumnInformation.verified.txt @@ -0,0 +1,7 @@ +{ + "Street": "123 Main St", + "xxx": { + "Lat": 40.7128, + "Lng": -74.006 + } +} \ No newline at end of file diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions/GetPropertiesTests.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions/GetPropertiesTests.cs index 606f10d..ce8dc9c 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions/GetPropertiesTests.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions/GetPropertiesTests.cs @@ -251,4 +251,351 @@ public void GetProperties_ComplexOwnedType_ReturnsCorrectColumnInformation() Assert.False(property.IsPrimaryKey); Assert.False(property.IsRowVersion); } + + [Fact] + public Task GetProperties_JsonComplexType_ReturnsCorrectColumnInformation() + { + // Arrange + var dbContext = new TestDbContext("", ""); + + // Act + var properties = dbContext.GetProperties(typeof(JsonComplexTypeOrder)); + + // Assert + Assert.Equal(2, properties.Count); + + var property = properties.First(p => p.PropertyName == "Id"); + Assert.Equal(typeof(int), property.PropertyType); + Assert.Equal("Id", property.ColumnName); + Assert.Equal("int", property.ColumnType); + Assert.Equal(ValueGenerated.OnAdd, property.ValueGenerated); + Assert.Null(property.DefaultValueSql); + Assert.True(property.IsPrimaryKey); + Assert.False(property.IsRowVersion); + + property = properties.First(p => p.PropertyName == "ShippingAddress"); + Assert.Equal(typeof(ComplexTypeAddress), property.PropertyType); + Assert.Equal("ShippingAddress", property.ColumnName); + Assert.Equal("nvarchar(max)", property.ColumnType); + Assert.Equal(ValueGenerated.Never, property.ValueGenerated); + Assert.Null(property.DefaultValueSql); + Assert.False(property.IsPrimaryKey); + Assert.False(property.IsRowVersion); + Assert.True(property.IsJson); + Assert.NotNull(property.JsonProperties); + + // Verify that the JsonProperties have correct structure + var jsonProperties = property.JsonProperties; + var flattenedJsonProperties = property.FlattenedJsonProperties; + Assert.Equal(2, jsonProperties.Count); // Street and Location + + var streetWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Street"); + Assert.NotNull(streetWriter); + Assert.Equal("Street", streetWriter.JsonPropertyName); + Assert.Equal("Street", streetWriter.FullJsonPropertyName); + Assert.Equal("ShippingAddress.Street", streetWriter.FullClrPropertyName); + Assert.Equal(typeof(string), streetWriter.PropertyType); + Assert.False(streetWriter.IsNestedComplexType); + + var locationWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Location"); + Assert.NotNull(locationWriter); + Assert.Equal("xxx", locationWriter.JsonPropertyName); // Mapped to "xxx" in TestDbContext + Assert.Equal("xxx", locationWriter.FullJsonPropertyName); + Assert.Equal("ShippingAddress.Location", locationWriter.FullClrPropertyName); + Assert.Equal(typeof(ComplexTypeLocation), locationWriter.PropertyType); + Assert.True(locationWriter.IsNestedComplexType); + Assert.NotNull(locationWriter.NestedProperties); + Assert.Equal(2, locationWriter.NestedProperties.Count); // Lat and Lng + + var latWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lat"); + Assert.NotNull(latWriter); + Assert.Equal("xxx.Lat", latWriter.FullJsonPropertyName); + Assert.Equal("ShippingAddress.Location.Lat", latWriter.FullClrPropertyName); + Assert.Equal(typeof(double), latWriter.PropertyType); + + var lngWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lng"); + Assert.NotNull(lngWriter); + Assert.Equal("xxx.Lng", lngWriter.FullJsonPropertyName); + Assert.Equal("ShippingAddress.Location.Lng", lngWriter.FullClrPropertyName); + Assert.Equal(typeof(double), lngWriter.PropertyType); + + // Verify serialization using JsonProperties + + var testOrder = new JsonComplexTypeOrder + { + Id = 1, + ShippingAddress = new ComplexTypeAddress + { + Street = "123 Main St", + Location = new ComplexTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + } + }; + + var json = JsonPropertyWriter.Write(testOrder, flattenedJsonProperties, indented: true); + Assert.NotNull(json); + Assert.Contains("Street", json); + Assert.Contains("123 Main St", json); + Assert.Contains("xxx", json); // Location is mapped to "xxx" + Assert.Contains("Lat", json); + Assert.Contains("Lng", json); + + return Verify(json); + } + + + + [Fact] + public Task GetProperties_JsonOwnedType_ReturnsCorrectColumnInformation() + { + // Arrange + var dbContext = new TestDbContext("", ""); + + // Act + var properties = dbContext.GetProperties(typeof(JsonOwnedTypeOrder)); + + // Assert + Assert.Equal(2, properties.Count); + + var property = properties.First(p => p.PropertyName == "Id"); + Assert.Equal(typeof(int), property.PropertyType); + Assert.Equal("Id", property.ColumnName); + Assert.Equal("int", property.ColumnType); + Assert.Equal(ValueGenerated.OnAdd, property.ValueGenerated); + Assert.Null(property.DefaultValueSql); + Assert.True(property.IsPrimaryKey); + Assert.False(property.IsRowVersion); + + property = properties.First(p => p.PropertyName == "ShippingAddress"); + Assert.Equal(typeof(OwnedTypeAddress), property.PropertyType); + Assert.Equal("ShippingAddress", property.ColumnName); + Assert.Equal("nvarchar(max)", property.ColumnType); + Assert.Equal(ValueGenerated.Never, property.ValueGenerated); + Assert.Null(property.DefaultValueSql); + Assert.False(property.IsPrimaryKey); + Assert.False(property.IsRowVersion); + Assert.True(property.IsJson); + Assert.NotNull(property.JsonProperties); + + // Verify that the JsonProperties have correct structure + var jsonProperties = property.JsonProperties; + var flattenedJsonProperties = property.FlattenedJsonProperties; + Assert.Equal(3, jsonProperties.Count); // Street and Location + + var streetWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Street"); + Assert.NotNull(streetWriter); + Assert.Equal("Street", streetWriter.JsonPropertyName); + Assert.Equal("Street", streetWriter.FullJsonPropertyName); + Assert.Equal("ShippingAddress.Street", streetWriter.FullClrPropertyName); + Assert.Equal(typeof(string), streetWriter.PropertyType); + Assert.False(streetWriter.IsNestedComplexType); + + var locationWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Location"); + Assert.NotNull(locationWriter); + Assert.Equal("xxx", locationWriter.JsonPropertyName); // Mapped to "xxx" in TestDbContext + Assert.Equal("xxx", locationWriter.FullJsonPropertyName); + Assert.Equal("ShippingAddress.Location", locationWriter.FullClrPropertyName); + Assert.Equal(typeof(OwnedTypeLocation), locationWriter.PropertyType); + Assert.True(locationWriter.IsNestedComplexType); + Assert.NotNull(locationWriter.NestedProperties); + Assert.Equal(3, locationWriter.NestedProperties.Count); // Lat and Lng + + var latWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lat"); + Assert.NotNull(latWriter); + Assert.Equal("xxx.Lat", latWriter.FullJsonPropertyName); + Assert.Equal("ShippingAddress.Location.Lat", latWriter.FullClrPropertyName); + Assert.Equal(typeof(double), latWriter.PropertyType); + + var lngWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lng"); + Assert.NotNull(lngWriter); + Assert.Equal("xxx.Lng", lngWriter.FullJsonPropertyName); + Assert.Equal("ShippingAddress.Location.Lng", lngWriter.FullClrPropertyName); + Assert.Equal(typeof(double), lngWriter.PropertyType); + + // Verify serialization using JsonProperties + var testOrder = new JsonOwnedTypeOrder + { + Id = 1, + ShippingAddress = new OwnedTypeAddress + { + Street = "123 Main St", + Location = new OwnedTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + } + }; + + var json = JsonPropertyWriter.Write(testOrder, flattenedJsonProperties, indented: true); + Assert.NotNull(json); + Assert.Contains("Street", json); + Assert.Contains("123 Main St", json); + Assert.Contains("xxx", json); // Location is mapped to "xxx" + Assert.Contains("Lat", json); + Assert.Contains("Lng", json); + + return Verify(json); + } + + [Fact] + public Task GetProperties_JsonComplexOwnedType_ReturnsCorrectColumnInformation() + { + // Arrange + var dbContext = new TestDbContext("", ""); + + // Act + var properties = dbContext.GetProperties(typeof(JsonComplexOwnedTypeOrder)); + + // Assert + Assert.Equal(3, properties.Count); + + var property = properties.First(p => p.PropertyName == "Id"); + Assert.Equal(typeof(int), property.PropertyType); + Assert.Equal("Id", property.ColumnName); + Assert.Equal("int", property.ColumnType); + Assert.Equal(ValueGenerated.OnAdd, property.ValueGenerated); + Assert.Null(property.DefaultValueSql); + Assert.True(property.IsPrimaryKey); + Assert.False(property.IsRowVersion); + + property = properties.First(p => p.PropertyName == "ComplexShippingAddress"); + Assert.Equal(typeof(ComplexTypeAddress), property.PropertyType); + Assert.Equal("ComplexShippingAddress", property.ColumnName); + Assert.Equal("nvarchar(max)", property.ColumnType); + Assert.Equal(ValueGenerated.Never, property.ValueGenerated); + Assert.Null(property.DefaultValueSql); + Assert.False(property.IsPrimaryKey); + Assert.False(property.IsRowVersion); + Assert.True(property.IsJson); + Assert.NotNull(property.JsonProperties); + + // Verify that the JsonProperties have correct structure + var jsonProperties = property.JsonProperties; + var flattenedJsonProperties = property.FlattenedJsonProperties; + Assert.Equal(2, jsonProperties.Count); // Street and Location + + var streetWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Street"); + Assert.NotNull(streetWriter); + Assert.Equal("Street", streetWriter.JsonPropertyName); + Assert.Equal("Street", streetWriter.FullJsonPropertyName); + Assert.Equal("ComplexShippingAddress.Street", streetWriter.FullClrPropertyName); + Assert.Equal(typeof(string), streetWriter.PropertyType); + Assert.False(streetWriter.IsNestedComplexType); + + var locationWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Location"); + Assert.NotNull(locationWriter); + Assert.Equal("xxx", locationWriter.JsonPropertyName); // Mapped to "xxx" in TestDbContext + Assert.Equal("xxx", locationWriter.FullJsonPropertyName); + Assert.Equal("ComplexShippingAddress.Location", locationWriter.FullClrPropertyName); + Assert.Equal(typeof(ComplexTypeLocation), locationWriter.PropertyType); + Assert.True(locationWriter.IsNestedComplexType); + Assert.NotNull(locationWriter.NestedProperties); + Assert.Equal(2, locationWriter.NestedProperties.Count); // Lat and Lng + + var latWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lat"); + Assert.NotNull(latWriter); + Assert.Equal("xxx.Lat", latWriter.FullJsonPropertyName); + Assert.Equal("ComplexShippingAddress.Location.Lat", latWriter.FullClrPropertyName); + Assert.Equal(typeof(double), latWriter.PropertyType); + + var lngWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lng"); + Assert.NotNull(lngWriter); + Assert.Equal("xxx.Lng", lngWriter.FullJsonPropertyName); + Assert.Equal("ComplexShippingAddress.Location.Lng", lngWriter.FullClrPropertyName); + Assert.Equal(typeof(double), lngWriter.PropertyType); + + + property = properties.First(p => p.PropertyName == "OwnedShippingAddress"); + Assert.Equal(typeof(OwnedTypeAddress), property.PropertyType); + Assert.Equal("OwnedShippingAddress", property.ColumnName); + Assert.Equal("nvarchar(max)", property.ColumnType); + Assert.Equal(ValueGenerated.Never, property.ValueGenerated); + Assert.Null(property.DefaultValueSql); + Assert.False(property.IsPrimaryKey); + Assert.False(property.IsRowVersion); + Assert.True(property.IsJson); + Assert.NotNull(property.JsonProperties); + + // Verify that the JsonProperties have correct structure + jsonProperties = property.JsonProperties; + flattenedJsonProperties = property.FlattenedJsonProperties; + Assert.Equal(3, jsonProperties.Count); // Street and Location + + streetWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Street"); + Assert.NotNull(streetWriter); + Assert.Equal("Street", streetWriter.JsonPropertyName); + Assert.Equal("Street", streetWriter.FullJsonPropertyName); + Assert.Equal("OwnedShippingAddress.Street", streetWriter.FullClrPropertyName); + Assert.Equal(typeof(string), streetWriter.PropertyType); + Assert.False(streetWriter.IsNestedComplexType); + + locationWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Location"); + Assert.NotNull(locationWriter); + Assert.Equal("xxx", locationWriter.JsonPropertyName); // Mapped to "xxx" in TestDbContext + Assert.Equal("xxx", locationWriter.FullJsonPropertyName); + Assert.Equal("OwnedShippingAddress.Location", locationWriter.FullClrPropertyName); + Assert.Equal(typeof(OwnedTypeLocation), locationWriter.PropertyType); + Assert.True(locationWriter.IsNestedComplexType); + Assert.NotNull(locationWriter.NestedProperties); + Assert.Equal(3, locationWriter.NestedProperties.Count); // Lat and Lng + + latWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lat"); + Assert.NotNull(latWriter); + Assert.Equal("xxx.Lat", latWriter.FullJsonPropertyName); + Assert.Equal("OwnedShippingAddress.Location.Lat", latWriter.FullClrPropertyName); + Assert.Equal(typeof(double), latWriter.PropertyType); + + lngWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lng"); + Assert.NotNull(lngWriter); + Assert.Equal("xxx.Lng", lngWriter.FullJsonPropertyName); + Assert.Equal("OwnedShippingAddress.Location.Lng", lngWriter.FullClrPropertyName); + Assert.Equal(typeof(double), lngWriter.PropertyType); + + + // Verify serialization using JsonProperties + var testOrder = new JsonComplexOwnedTypeOrder + { + Id = 1, + ComplexShippingAddress = new ComplexTypeAddress + { + Street = "123 Main St", + Location = new ComplexTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + }, + OwnedShippingAddress = new OwnedTypeAddress + { + Street = "123 Main St", + Location = new OwnedTypeLocation + { + Lat = 40.7128, + Lng = -74.0060 + } + } + }; + + var json1 = JsonPropertyWriter.Write(testOrder, properties.First(p => p.PropertyName == "ComplexShippingAddress").FlattenedJsonProperties, indented: true); + Assert.NotNull(json1); + Assert.Contains("Street", json1); + Assert.Contains("123 Main St", json1); + Assert.Contains("xxx", json1); // Location is mapped to "xxx" + Assert.Contains("Lat", json1); + Assert.Contains("Lng", json1); + + var json2 = JsonPropertyWriter.Write(testOrder, properties.First(p => p.PropertyName == "OwnedShippingAddress").FlattenedJsonProperties, indented: true); + Assert.NotNull(json2); + Assert.Contains("Street", json2); + Assert.Contains("123 Main St", json2); + Assert.Contains("xxx", json2); // Location is mapped to "xxx" + Assert.Contains("Lat", json2); + Assert.Contains("Lng", json2); + + return Verify(json1 + Environment.NewLine + json2); + } } diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks/ColumnInfor.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks/ColumnInfor.cs index a93402e..2d58756 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks/ColumnInfor.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks/ColumnInfor.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore.Metadata; using System; +using System.Collections.Generic; namespace EntityFrameworkCore.SqlServer.SimpleBulks; @@ -22,4 +23,10 @@ public class ColumnInfor public bool IsRowVersion { get; init; } public ValueConverter? ValueConverter { get; set; } + + public bool IsJson { get; set; } + + public IReadOnlyList? JsonProperties { get; init; } + + public IReadOnlyDictionary FlattenedJsonProperties { get; init; } } diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks/Extensions/DbContextExtensions.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks/Extensions/DbContextExtensions.cs index 0e5726e..14668ed 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks/Extensions/DbContextExtensions.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks/Extensions/DbContextExtensions.cs @@ -33,6 +33,8 @@ public static class DbContextExtensions private static readonly ConcurrentDictionary> _allPropertyNamesWithoutRowVersionsCache = []; private static readonly ConcurrentDictionary> _valueConvertersCache = []; private static readonly ConcurrentDictionary _discriminatorCache = []; + private static readonly ConcurrentDictionary>> _jsonPropertiesCache = []; + private static readonly ConcurrentDictionary>> _flattenedJsonPropertiesCache = []; public static TableInfor GetTableInfor(this DbContext dbContext) { @@ -59,7 +61,9 @@ public static TableInfor GetTableInfor(this DbContext dbContext) Name = outputIdColumn.PropertyName, Mode = outputIdColumn.PropertyType == typeof(Guid) && string.IsNullOrEmpty(outputIdColumn.DefaultValueSql) ? OutputIdMode.ClientGenerated : OutputIdMode.ServerGenerated }, - Discriminator = GetDiscriminator(entityType) + Discriminator = GetDiscriminator(entityType), + JsonProperties = dbContext.GetJsonProperties(key.EntityType), + FlattenedJsonProperties = dbContext.GetFlattenedJsonProperties(key.EntityType) }; return tableInfo; }); @@ -130,7 +134,15 @@ public static IReadOnlyList GetProperties(this DbContext dbContext, foreach (var complexProperty in complexProperties) { - AddComplexProperty(data, complexProperty, tableId, complexProperty.Name + "."); + if (complexProperty.ComplexType.IsMappedToJson()) + { + // For JSON-mapped complex types, add the complex property itself as a single JSON column + AddJsonComplexProperty(data, complexProperty, tableId); + } + else + { + AddComplexProperty(data, complexProperty, tableId, complexProperty.Name + "."); + } } var ownedProperties = entityType.GetNavigations().Where(n => n.TargetEntityType.IsOwned()); @@ -142,7 +154,15 @@ public static IReadOnlyList GetProperties(this DbContext dbContext, continue; } - AddOwnedProperty(data, ownedProperty.TargetEntityType, tableId, ownedProperty.Name + "."); + if (ownedProperty.TargetEntityType.IsMappedToJson()) + { + // For owned entities mapped to JSON, add the owned navigation itself as a single JSON column + AddJsonOwnedProperty(data, ownedProperty); + } + else + { + AddOwnedProperty(data, ownedProperty.TargetEntityType, tableId, ownedProperty.Name + "."); + } } return data; @@ -172,6 +192,151 @@ private static List GetColumnInfos(Type type, IEnumerable columnInfors, IComplexProperty complexProperty, StoreObjectIdentifier storeObjectIdentifier) + { + var containerColumnName = complexProperty.ComplexType.GetContainerColumnName(); + var containerColumnType = complexProperty.ComplexType.GetContainerColumnType() ?? "nvarchar(max)"; + + // Build JsonProperties using EF Core's GetJsonValueReaderWriter for each property + var jsonProperties = BuildJsonProperties(complexProperty.ComplexType, clrPrefix: complexProperty.Name + "."); + + columnInfors.Add(new ColumnInfor + { + PropertyName = complexProperty.Name, + PropertyType = complexProperty.ClrType, + ColumnName = containerColumnName, + ColumnType = containerColumnType, + ValueGenerated = ValueGenerated.Never, + DefaultValueSql = null, + IsPrimaryKey = false, + IsRowVersion = false, + ValueConverter = null, + IsJson = true, + JsonProperties = jsonProperties, + FlattenedJsonProperties = JsonProperty.FlattenJsonProperties(jsonProperties) + }); + } + + private static List BuildJsonProperties(IComplexType complexType, string clrPrefix = "", string jsonPrefix = "") + { + var jsonProperties = new List(); + + // Add writers for scalar properties + foreach (var property in complexType.GetProperties()) + { + var jsonPropertyName = property.GetJsonPropertyName() ?? property.Name; + var readerWriter = property.GetJsonValueReaderWriter() ?? property.GetTypeMapping().JsonValueReaderWriter; + + jsonProperties.Add(new JsonProperty + { + JsonPropertyName = jsonPropertyName, + ClrPropertyName = property.Name, + FullJsonPropertyName = $"{jsonPrefix}{jsonPropertyName}", + FullClrPropertyName = $"{clrPrefix}{property.Name}", + PropertyType = property.ClrType, + ReaderWriter = readerWriter, + NestedProperties = null + }); + } + + // Add writers for nested complex properties + foreach (var nestedComplexProperty in complexType.GetComplexProperties()) + { + var jsonPropertyName = nestedComplexProperty.GetJsonPropertyName() ?? nestedComplexProperty.Name; + var fullJsonPath = $"{jsonPrefix}{jsonPropertyName}"; + var fullClrPropertyName = $"{clrPrefix}{nestedComplexProperty.Name}"; + var nestedJsonProperties = BuildJsonProperties(nestedComplexProperty.ComplexType, fullClrPropertyName + ".", fullJsonPath + "."); + + jsonProperties.Add(new JsonProperty + { + JsonPropertyName = jsonPropertyName, + ClrPropertyName = nestedComplexProperty.Name, + FullJsonPropertyName = fullJsonPath, + FullClrPropertyName = fullClrPropertyName, + PropertyType = nestedComplexProperty.ClrType, + ReaderWriter = null, + NestedProperties = nestedJsonProperties + }); + } + + return jsonProperties; + } + + private static void AddJsonOwnedProperty(List columnInfors, INavigation ownedNavigation) + { + var containerColumnName = ownedNavigation.TargetEntityType.GetContainerColumnName(); + var containerColumnType = ownedNavigation.TargetEntityType.GetContainerColumnType() ?? "nvarchar(max)"; + + var jsonProperties = BuildJsonProperties(ownedNavigation.TargetEntityType, clrPrefix: ownedNavigation.Name + "."); + + columnInfors.Add(new ColumnInfor + { + PropertyName = ownedNavigation.Name, + PropertyType = ownedNavigation.TargetEntityType.ClrType, + ColumnName = containerColumnName, + ColumnType = containerColumnType, + ValueGenerated = ValueGenerated.Never, + DefaultValueSql = null, + IsPrimaryKey = false, + IsRowVersion = false, + ValueConverter = null, + IsJson = true, + JsonProperties = jsonProperties, + FlattenedJsonProperties = JsonProperty.FlattenJsonProperties(jsonProperties) + }); + } + + private static List BuildJsonProperties(IEntityType entityType, string clrPrefix = "", string jsonPrefix = "") + { + var jsonProperties = new List(); + + // Add writers for scalar properties on the owned entity type + foreach (var property in entityType.GetProperties()) + { + var jsonPropertyName = property.GetJsonPropertyName() ?? property.Name; + var readerWriter = property.GetJsonValueReaderWriter() ?? property.GetTypeMapping().JsonValueReaderWriter; + + jsonProperties.Add(new JsonProperty + { + JsonPropertyName = jsonPropertyName, + ClrPropertyName = property.Name, + FullJsonPropertyName = $"{jsonPrefix}{jsonPropertyName}", + FullClrPropertyName = $"{clrPrefix}{property.Name}", + PropertyType = property.ClrType, + IsShadowProperty = property.IsShadowProperty(), + IsForeignKey = property.IsForeignKey(), + ReaderWriter = readerWriter, + NestedProperties = null + }); + } + + var ownedProperties = entityType.GetNavigations().Where(n => n.TargetEntityType.IsOwned()); + + // Add writers for complex properties on the owned entity type + foreach (var nestedOwnedProperty in ownedProperties) + { + // For complex properties mapped to JSON inside the owned entity, add a single JSON writer + var jsonPropertyName = nestedOwnedProperty.TargetEntityType.GetJsonPropertyName() ?? nestedOwnedProperty.Name; + var fullJsonPath = $"{jsonPrefix}{jsonPropertyName}"; + var fullClrPropertyName = $"{clrPrefix}{nestedOwnedProperty.Name}"; + + var nestedJsonProperties = BuildJsonProperties(nestedOwnedProperty.TargetEntityType, fullClrPropertyName + ".", fullJsonPath + "."); + + jsonProperties.Add(new JsonProperty + { + JsonPropertyName = jsonPropertyName, + ClrPropertyName = nestedOwnedProperty.Name, + FullJsonPropertyName = fullJsonPath, + FullClrPropertyName = fullClrPropertyName, + PropertyType = nestedOwnedProperty.ClrType, + ReaderWriter = null, + NestedProperties = nestedJsonProperties + }); + } + + return jsonProperties; + } + private static void AddComplexProperty(List columnInfors, IComplexProperty complexProperty, StoreObjectIdentifier storeObjectIdentifier, string prefix = "") { var entityProperties = complexProperty.ComplexType.GetProperties(); @@ -182,7 +347,15 @@ private static void AddComplexProperty(List columnInfors, IComplexP foreach (var nestedComplexProperty in nestedComplexProperties) { - AddComplexProperty(columnInfors, nestedComplexProperty, storeObjectIdentifier, prefix + nestedComplexProperty.Name + "."); + if (complexProperty.ComplexType.IsMappedToJson()) + { + // For JSON-mapped complex types, add the complex property itself as a single JSON column + AddJsonComplexProperty(columnInfors, nestedComplexProperty, storeObjectIdentifier); + } + else + { + AddComplexProperty(columnInfors, nestedComplexProperty, storeObjectIdentifier, prefix + nestedComplexProperty.Name + "."); + } } } @@ -216,6 +389,7 @@ private static ValueConverter GetValueConverter(IProperty property) return new ValueConverter { + PropertyName = property.Name, ProviderClrType = converter.ProviderClrType, ConvertToProvider = converter.ConvertToProvider, ConvertFromProvider = converter.ConvertFromProvider @@ -314,7 +488,47 @@ public static IReadOnlyDictionary GetValueConverters(thi return _valueConvertersCache.GetOrAdd(cacheKey, (key) => { var properties = dbContext.GetProperties(key.EntityType); - return properties.Where(x => x.ValueConverter != null).ToFrozenDictionary(x => x.PropertyName, x => x.ValueConverter); + + var jsonValueConverters = properties.Where(x => x.IsJson).Select(x => new + { + x.PropertyName, + ValueConverter = new JsonValueConverter + { + PropertyName = x.PropertyName, + ProviderClrType = typeof(string), + JsonProperties = x.JsonProperties, + FlattenedJsonProperties = x.FlattenedJsonProperties + } + }); + + var valueConverters = properties.Where(x => x.ValueConverter != null).ToDictionary(x => x.PropertyName, x => x.ValueConverter); + + foreach (var jsonConverter in jsonValueConverters) + { + valueConverters[jsonConverter.PropertyName] = jsonConverter.ValueConverter; + } + + return valueConverters.ToFrozenDictionary(); + }); + } + + public static IReadOnlyDictionary> GetJsonProperties(this DbContext dbContext, Type type) + { + var cacheKey = new CacheKey(dbContext.GetType(), type); + return _jsonPropertiesCache.GetOrAdd(cacheKey, (key) => + { + var properties = dbContext.GetProperties(key.EntityType); + return properties.Where(x => x.IsJson).ToFrozenDictionary(x => x.PropertyName, x => x.JsonProperties); + }); + } + + public static IReadOnlyDictionary> GetFlattenedJsonProperties(this DbContext dbContext, Type type) + { + var cacheKey = new CacheKey(dbContext.GetType(), type); + return _flattenedJsonPropertiesCache.GetOrAdd(cacheKey, (key) => + { + var properties = dbContext.GetProperties(key.EntityType); + return properties.Where(x => x.IsJson).ToFrozenDictionary(x => x.PropertyName, x => x.FlattenedJsonProperties); }); } diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks/JsonProperty.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks/JsonProperty.cs new file mode 100644 index 0000000..03d51b1 --- /dev/null +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks/JsonProperty.cs @@ -0,0 +1,56 @@ +using Microsoft.EntityFrameworkCore.Storage.Json; +using System; +using System.Collections.Generic; + +namespace EntityFrameworkCore.SqlServer.SimpleBulks; + +public class JsonProperty +{ + public string JsonPropertyName { get; init; } + + public string ClrPropertyName { get; init; } + + public string FullJsonPropertyName { get; init; } + + public string FullClrPropertyName { get; init; } + + public bool IsShadowProperty { get; init; } + + public bool IsForeignKey { get; init; } + + public Type PropertyType { get; init; } + + public JsonValueReaderWriter? ReaderWriter { get; init; } + + public IReadOnlyList? NestedProperties { get; init; } + + public bool IsNestedComplexType => NestedProperties != null && NestedProperties.Count > 0; + + + public static IReadOnlyDictionary FlattenJsonProperties(IReadOnlyList? jsonProperties) + { + if (jsonProperties == null || jsonProperties.Count == 0) + { + return new Dictionary(); + } + + var result = new Dictionary(); + FlattenJsonProperties(jsonProperties, result); + return result; + } + + private static void FlattenJsonProperties(IReadOnlyList jsonProperties, Dictionary result) + { + foreach (var jsonProperty in jsonProperties) + { + if (jsonProperty.IsNestedComplexType) + { + FlattenJsonProperties(jsonProperty.NestedProperties, result); + } + else + { + result[jsonProperty.FullClrPropertyName] = jsonProperty; + } + } + } +} diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks/JsonPropertyWriter.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks/JsonPropertyWriter.cs new file mode 100644 index 0000000..88a26fa --- /dev/null +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks/JsonPropertyWriter.cs @@ -0,0 +1,180 @@ +using EntityFrameworkCore.SqlServer.SimpleBulks; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json; +using SimpleBulksJsonProperty = EntityFrameworkCore.SqlServer.SimpleBulks.JsonProperty; + +public static class JsonPropertyWriter +{ + const int MaxSegments = 32; // adjust if deeper nesting is possible + + public static string Write(T item, IReadOnlyDictionary jsonProperties, bool indented = false) + { + var buffer = new ArrayBufferWriter(); + + using var writer = new Utf8JsonWriter(buffer, new JsonWriterOptions + { + Indented = indented + }); + + writer.WriteStartObject(); + + Span prevStarts = stackalloc int[MaxSegments]; + Span prevLens = stackalloc int[MaxSegments]; + int prevCount = 0; + string prevKey = ""; + + foreach (var (propertyName, jsonProperty) in jsonProperties) + { + if (jsonProperty.IsShadowProperty && jsonProperty.IsForeignKey) + continue; // skip shadow FK properties + + ReadOnlySpan span = jsonProperty.FullJsonPropertyName.AsSpan(); + + Span starts = stackalloc int[MaxSegments]; + Span lens = stackalloc int[MaxSegments]; + + int count = ParseSegments(span, starts, lens); + + int maxObjSeg = Math.Min(count - 1, prevCount - 1); + + int common = 0; + while (common < maxObjSeg && + SegmentEquals(prevKey.AsSpan(), prevStarts[common], prevLens[common], + span, starts[common], lens[common])) + { + common++; + } + + // close objects + for (int i = prevCount - 2; i >= common; i--) + writer.WriteEndObject(); + + // open objects + for (int i = common; i < count - 1; i++) + { + writer.WritePropertyName(span.Slice(starts[i], lens[i])); + writer.WriteStartObject(); + } + + // write value + writer.WritePropertyName(span.Slice(starts[count - 1], lens[count - 1])); + WriteValue(writer, item, jsonProperty); + + // copy current segments to prev + for (int i = 0; i < count; i++) + { + prevStarts[i] = starts[i]; + prevLens[i] = lens[i]; + } + + prevKey = jsonProperty.FullJsonPropertyName; + prevCount = count; + } + + for (int i = prevCount - 2; i >= 0; i--) + writer.WriteEndObject(); + + writer.WriteEndObject(); + writer.Flush(); + + return Encoding.UTF8.GetString(buffer.WrittenSpan); + } + + static int ParseSegments(ReadOnlySpan key, Span starts, Span lens) + { + int seg = 0; + int start = 0; + + for (int i = 0; i < key.Length; i++) + { + if (key[i] == '.') + { + starts[seg] = start; + lens[seg] = i - start; + seg++; + start = i + 1; + } + } + + starts[seg] = start; + lens[seg] = key.Length - start; + seg++; + + return seg; + } + + static bool SegmentEquals( + ReadOnlySpan a, int aStart, int aLen, + ReadOnlySpan b, int bStart, int bLen) + { + if (aLen != bLen) return false; + return a.Slice(aStart, aLen).SequenceEqual(b.Slice(bStart, bLen)); + } + + static void WriteValue(Utf8JsonWriter writer, T? item, SimpleBulksJsonProperty jsonProperty) + { + var value = PropertiesCache.GetPropertyValue(jsonProperty.FullClrPropertyName, item, null); + + if (jsonProperty.ReaderWriter != null) + { + jsonProperty.ReaderWriter.ToJson(writer, value); + return; + } + + switch (value) + { + case null: + writer.WriteNullValue(); + break; + + case string s: + writer.WriteStringValue(s); + break; + + case int i: + writer.WriteNumberValue(i); + break; + + case long l: + writer.WriteNumberValue(l); + break; + + case double d: + writer.WriteNumberValue(d); + break; + + case float f: + writer.WriteNumberValue(f); + break; + + case decimal m: + writer.WriteNumberValue(m); + break; + + case bool b: + writer.WriteBooleanValue(b); + break; + + case DateTime dt: + writer.WriteStringValue(dt); + break; + + case DateTimeOffset dto: + writer.WriteStringValue(dto); + break; + + case Guid g: + writer.WriteStringValue(g); + break; + + default: + // fallback for complex types + JsonSerializer.Serialize(writer, value); + break; + } + } +} \ No newline at end of file diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks/PropertiesCache.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks/PropertiesCache.cs index 545e3d7..986097e 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks/PropertiesCache.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks/PropertiesCache.cs @@ -287,6 +287,16 @@ public static object GetPropertyValue(string propName, T item, IReadOnlyDictiona if (valueConverters != null && valueConverters.TryGetValue(propName, out var converter)) { + if (converter is JsonValueConverter jsonValueConverter) + { + if (value == null) + { + return null; + } + + return JsonPropertyWriter.Write(item, jsonValueConverter.FlattenedJsonProperties); + } + return converter.ConvertToProvider(value); } diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks/SqlTableInforBuilder.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks/SqlTableInforBuilder.cs index 9754fb6..fda757a 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks/SqlTableInforBuilder.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks/SqlTableInforBuilder.cs @@ -168,6 +168,7 @@ public SqlTableInforBuilder ConfigurePropertyConversion var propertyName = nameSelector.Body.GetMemberName(); _valueConverters[propertyName] = new ValueConverter { + PropertyName = propertyName, ProviderClrType = typeof(TProvider), ConvertToProvider = obj => convertToProvider((TProperty?)obj), ConvertFromProvider = obj => convertFromProvider((TProvider?)obj), @@ -205,6 +206,36 @@ public SqlTableInforBuilder ConfigureDiscriminator(Expression ConfigureJsonProperty(string propertyName, Func convertToJson) + { + _valueConverters[propertyName] = new ValueConverter + { + PropertyName = propertyName, + ProviderClrType = typeof(string), + ConvertToProvider = obj => convertToJson((TProperty?)obj) + }; + + if (!_propertyNames.Contains(propertyName)) + { + _propertyNames.Add(propertyName); + } + + if (!_insertablePropertyNames.Contains(propertyName)) + { + _insertablePropertyNames.Add(propertyName); + } + + return this; + } + + public SqlTableInforBuilder ConfigureJsonProperty(Expression> nameSelector, Func convertToJson) + { + var propertyName = nameSelector.Body.GetMemberName(); + + return ConfigureJsonProperty(propertyName, convertToJson); + } + + public SqlTableInfor Build() { if (_outputId?.Mode == OutputIdMode.ServerGenerated && _insertablePropertyNames.Contains(_outputId.Name)) diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks/TableInfor.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks/TableInfor.cs index e8c4aca..32b96e2 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks/TableInfor.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks/TableInfor.cs @@ -32,6 +32,10 @@ public abstract class TableInfor public Discriminator Discriminator { get; init; } + public IReadOnlyDictionary> JsonProperties { get; init; } + + public IReadOnlyDictionary> FlattenedJsonProperties { get; init; } + public string GetDbColumnName(string propertyName) { if (ColumnNameMappings == null) diff --git a/src/EntityFrameworkCore.SqlServer.SimpleBulks/ValueConverter.cs b/src/EntityFrameworkCore.SqlServer.SimpleBulks/ValueConverter.cs index c4917d6..0bc5fe4 100644 --- a/src/EntityFrameworkCore.SqlServer.SimpleBulks/ValueConverter.cs +++ b/src/EntityFrameworkCore.SqlServer.SimpleBulks/ValueConverter.cs @@ -1,9 +1,12 @@ using System; +using System.Collections.Generic; namespace EntityFrameworkCore.SqlServer.SimpleBulks; public class ValueConverter { + public string PropertyName { get; init; } + public Type ProviderClrType { get; init; } public Func ConvertToProvider { get; init; } @@ -13,11 +16,11 @@ public class ValueConverter public ValueConverter() { } - - public ValueConverter(Type providerClrType, Func convertToProvider, Func convertFromProvider) - { - ProviderClrType = providerClrType; - ConvertToProvider = convertToProvider; - ConvertFromProvider = convertFromProvider; - } } + +public class JsonValueConverter : ValueConverter +{ + public IReadOnlyList? JsonProperties { get; init; } + + public IReadOnlyDictionary FlattenedJsonProperties { get; init; } +} \ No newline at end of file diff --git a/src/global.json b/src/global.json index 501e79a..f72210c 100644 --- a/src/global.json +++ b/src/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.100", + "version": "10.0.100", "rollForward": "latestFeature" } } \ No newline at end of file