Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions N.EntityFrameworkCore.Extensions.Test/Data/Address.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N.EntityFrameworkCore.Extensions.Test.Data;
[ComplexType]
public class Address
{
public required string Line1 { get; set; }
public string? Line2 { get; set; }

Check warning on line 13 in N.EntityFrameworkCore.Extensions.Test/Data/Address.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 13 in N.EntityFrameworkCore.Extensions.Test/Data/Address.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
public required string City { get; set; }
public required string Country { get; set; }
public required string PostCode { get; set; }
}
17 changes: 17 additions & 0 deletions N.EntityFrameworkCore.Extensions.Test/Data/OrderWithComplexType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N.EntityFrameworkCore.Extensions.Test.Data;
public class OrderWithComplexType
{
[Key]
public long Id { get; set; }
[Required]
public Address ShippingAddress { get; set; }
[Required]
public Address BillingAddress { get; set; }
}
6 changes: 6 additions & 0 deletions N.EntityFrameworkCore.Extensions.Test/Data/TestDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class TestDbContext : DbContext
public virtual DbSet<ProductWithComplexKey> ProductsWithComplexKey { get; set; }
public virtual DbSet<ProductWithTrigger> ProductsWithTrigger { get; set; }
public virtual DbSet<Order> Orders { get; set; }
public virtual DbSet<OrderWithComplexType> OrdersWithComplexType { get; set; }
public virtual DbSet<TpcPerson> TpcPeople { get; set; }
public virtual DbSet<TphPerson> TphPeople { get; set; }
public virtual DbSet<TphCustomer> TphCustomers { get; set; }
Expand All @@ -38,6 +39,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<Order>().Property<DateTime>("DbModifiedDateTime").HasComputedColumnSql("getdate()");
modelBuilder.Entity<Order>().Property<bool>(p => p.DbActive).HasDefaultValueSql("((1))");
modelBuilder.Entity<Order>().Property(p => p.Status).HasConversion<string>();
modelBuilder.Entity<OrderWithComplexType>(b =>
{
b.ComplexProperty(e => e.BillingAddress);
b.ComplexProperty(e => e.ShippingAddress);
});
modelBuilder.Entity<TpcPerson>().UseTpcMappingStrategy();
modelBuilder.Entity<TpcCustomer>().ToTable("TpcCustomer");
modelBuilder.Entity<TpcVendor>().ToTable("TpcVendor");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,38 @@ public void With_Complex_Key()
Assert.IsTrue(newTotal - oldTotal == rowsInserted, "The new count minus the old count should match the number of rows inserted.");
}
[TestMethod]
public void With_Complex_Type()
{
var dbContext = SetupDbContext(true);
var orders = new List<OrderWithComplexType>();
for (int i = 1; i < 1000; i++)
{
orders.Add(new OrderWithComplexType {
Id = i,
ShippingAddress = new Address
{
Line1 = $"123 Main St, {i}",
City = "Atlanta",
Country = "USA",
PostCode = "30303"
},
BillingAddress = new Address
{
Line1 = $"456 Oak St, {i}",
City = "Atlanta",
Country = "USA",
PostCode = "30303"
}
});
}
int oldTotal = dbContext.OrdersWithComplexType.Count();
int rowsInserted = dbContext.BulkInsert(orders);
int newTotal = dbContext.OrdersWithComplexType.Count();

Assert.IsTrue(rowsInserted == orders.Count, "The number of rows inserted must match the count of order list");
Assert.IsTrue(newTotal - oldTotal == rowsInserted, "The new count minus the old count should match the number of rows inserted.");
}
[TestMethod]
public void With_Default_Options()
{
var dbContext = SetupDbContext(false);
Expand Down
Loading