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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class TestDbContext : DbContext
public virtual DbSet<ProductCategory> ProductCategories { get; set; }
public virtual DbSet<ProductWithCustomSchema> ProductsWithCustomSchema { get; set; }
public virtual DbSet<ProductWithComplexKey> ProductsWithComplexKey { get; set; }
public virtual DbSet<ProductWithTrigger> ProductsWithTrigger { get; set; }
public virtual DbSet<Order> Orders { get; set; }
public virtual DbSet<TpcPerson> TpcPeople { get; set; }
public virtual DbSet<TphPerson> TphPeople { get; set; }
Expand Down Expand Up @@ -49,6 +50,5 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
t.ComplexProperty(p => p.Position).IsRequired();
t.Property(p => p.Color).HasConversion(x => x.ToArgb(), x => Color.FromArgb(x));
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,22 @@ public void With_Proxy_Type()
Assert.IsTrue(newTotal - oldTotal == rowsInserted, "The new count minus the old count should match the number of rows inserted.");
}
[TestMethod]
public void With_Trigger()
{
var dbContext = SetupDbContext(false);
var products = new List<ProductWithTrigger>();
for (int i = 1; i < 1000; i++)
{
products.Add(new ProductWithTrigger { Id = i.ToString(), Price = 1.57M, StatusString="InStock" });
}
int rowsInserted = dbContext.BulkInsert(products, options => {
options.AutoMapOutput = false;
options.BulkCopyOptions = SqlBulkCopyOptions.FireTriggers;
});

Assert.IsTrue(rowsInserted == products.Count, "The number of rows inserted must match the count of products");
}
[TestMethod]
public void With_ValueGenerated_Default()
{
var dbContext = SetupDbContext(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using Microsoft.EntityFrameworkCore;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using N.EntityFrameworkCore.Extensions.Test.Data;
using N.EntityFrameworkCore.Extensions.Test.Data.Enums;
Expand All @@ -28,10 +29,12 @@ public void Init()
protected TestDbContext SetupDbContext(bool populateData, PopulateDataMode mode = PopulateDataMode.Normal)
{
TestDbContext dbContext = new TestDbContext();
dbContext.Database.Migrate();
dbContext.Orders.Truncate();
dbContext.Products.Truncate();
dbContext.ProductCategories.Clear();
dbContext.ProductsWithCustomSchema.Truncate();
dbContext.ProductsWithTrigger.Truncate();
dbContext.Database.ClearTable("TpcCustomer");
dbContext.Database.ClearTable("TpcVendor");
dbContext.TphPeople.Truncate();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace N.EntityFrameworkCore.Extensions.Test.Migrations
{
public partial class Initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("CREATE TRIGGER trgProductWithTriggers\r\nON ProductsWithTrigger\r\nFOR INSERT, UPDATE, DELETE\r\nAS\r\nBEGIN\r\n PRINT 1 END");
}

protected override void Down(MigrationBuilder migrationBuilder)
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using N.EntityFrameworkCore.Extensions.Test.Data;

#nullable disable

namespace N.EntityFrameworkCore.Extensions.Test.Migrations
{
[DbContext(typeof(TestDbContext))]
partial class TestDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
Expand Down