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
3 changes: 3 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:

Expand Down
80 changes: 80 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Manual workflow: publish to NuGet and create a GitHub release with source zip.
# Run from Actions tab → "Publish and Release" → "Run workflow".
# Required secrets: NUGET_API_KEY (https://www.nuget.org/account/apikeys)

name: Publish and Release

on:
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g. 8.0.0.x). Tag will be v{version}.'
required: true
type: string
nuget_publish:
description: 'Publish package to NuGet.org'
required: false
default: true
type: boolean

env:
NUGET_SOURCE: 'https://api.nuget.org/v3/index.json'

jobs:
publish-and-release:
runs-on: windows-latest
permissions:
contents: write # create tag and release, upload assets

steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore -c Release

- name: Pack (ensure .nupkg output)
run: dotnet pack N.EntityFrameworkCore.Extensions/N.EntityFrameworkCore.Extensions.csproj --no-build -c Release -o out
id: pack

- name: Publish to NuGet
if: ${{ inputs.nuget_publish }}
run: dotnet nuget push .\out\*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source ${{ env.NUGET_SOURCE }} --skip-duplicate
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}

- name: Create source zip
run: |
$tag = "v${{ inputs.version }}"
git archive --format=zip --output=source-$tag.zip HEAD
echo "SOURCE_ZIP=source-$tag.zip" >> $env:GITHUB_ENV
echo "ARCHIVE_NAME=source-$tag.zip" >> $env:GITHUB_ENV

- name: Get .nupkg path
id: nupkg
run: |
$nupkg = Get-ChildItem -Path out -Filter "*.nupkg" | Select-Object -First 1
echo "path=$($nupkg.FullName)" >> $env:GITHUB_OUTPUT
echo "name=$($nupkg.Name)" >> $env:GITHUB_OUTPUT

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ inputs.version }}
name: Release v${{ inputs.version }}
generate_release_notes: true
files: |
${{ env.ARCHIVE_NAME }}
${{ steps.nupkg.outputs.path }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,15 @@ public void With_Trigger()
{
products.Add(new ProductWithTrigger { Id = i.ToString(), Price = 1.57M, StatusString="InStock" });
}
int rowsInserted = dbContext.BulkInsert(products, options => {

//The return int from BulkInsert() will be off when using triggers
dbContext.BulkInsert(products, options => {
options.AutoMapOutput = false;
options.BulkCopyOptions = SqlBulkCopyOptions.FireTriggers;
});
var rowsInserted = dbContext.ProductsWithTrigger.Count();

Assert.IsTrue(rowsInserted == products.Count, "The number of rows inserted must match the count of products");
Assert.IsTrue(rowsInserted == products.Count , $"The number of rows inserted must match the count of products ({rowsInserted}!={products.Count})");
}
[TestMethod]
public void With_ValueGenerated_Default()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void With_Add_Changes()
int rowsAffected = dbContext.BulkSaveChanges();
int newTotalCount = dbContext.Orders.Where(o => o.Price == 10.57M).Count();

Assert.IsTrue(ordersToAdd.Where(o => o.Id <= 0).Count() == 0, "Primary key should have been updated for all entities");
Assert.IsTrue(rowsAffected == ordersToAdd.Count, "The number of rows affected must equal the sum of entities added, deleted and updated");
Assert.IsTrue(oldTotalCount + ordersToAdd.Count == newTotalCount, "The number of orders to add did not match what was expected.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public async Task With_Add_Changes()
int rowsAffected = await dbContext.BulkSaveChangesAsync();
int newTotalCount = dbContext.Orders.Where(o => o.Price == 10.57M).Count();

Assert.IsTrue(ordersToAdd.Where(o => o.Id <= 0).Count() == 0, "Primary key should have been updated for all entities");
Assert.IsTrue(rowsAffected == ordersToAdd.Count, "The number of rows affected must equal the sum of entities added, deleted and updated");
Assert.IsTrue(oldTotalCount + ordersToAdd.Count == newTotalCount, "The number of orders to add did not match what was expected.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.SDK" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
<PackageReference Include="Microsoft.NET.Test.SDK" Version="18.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="4.1.0" />
<PackageReference Include="MSTest.TestFramework" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 7 additions & 2 deletions N.EntityFrameworkCore.Extensions/Data/DbContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
Expand Down Expand Up @@ -247,8 +248,12 @@ internal static void SetStoreGeneratedValues<T>(this DbContext context, T entity
{
foreach (var property in properties)
{
if (!property.IsPrimaryKey() ||
(property.IsPrimaryKey() && updateEntry.EntityState == EntityState.Detached))
if((updateEntry.EntityState == EntityState.Added &&
(property.ValueGenerated == ValueGenerated.OnAdd|| property.ValueGenerated == ValueGenerated.OnAddOrUpdate)) ||
(updateEntry.EntityState == EntityState.Modified &&
(property.ValueGenerated == ValueGenerated.OnUpdate || property.ValueGenerated == ValueGenerated.OnAddOrUpdate)) ||
updateEntry.EntityState == EntityState.Detached
)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>8.0.0.12</Version>
<Version>8.0.0.13</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageProjectUrl>https://github.com/NorthernLight1/N.EntityFrameworkCore.Extensions/</PackageProjectUrl>
<Authors>Northern25</Authors>
<Copyright>Copyright © 2024</Copyright>
<Copyright>Copyright © 2026</Copyright>
<Company />
<Description>N.EntityFrameworkCore.Extensions extends your DbContext in EF Core with high-performance bulk operations: BulkDelete, BulkInsert, BulkMerge, BulkSync, BulkUpdate, Fetch, DeleteFromQuery, InsertFromQuery, UpdateFromQuery.

Expand Down
Loading