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
14 changes: 14 additions & 0 deletions CSM Database Core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# CSM Database Core CHANGELOG

## [6.0.4] - 18.06-2026

### Fixes

- Fixed [DepotBase] [Update] method issue that was causing not relation inclussion on original entity object.

#### Dependencies

| Package | Previous Version | New Version |
|:----------------------------------------|:----------------:|:---------------:|
| CSM.Foundation.Core | 4.0.0 | 4.0.0 |
| Microsoft.EntityFrameworkCore | 10.0.8 | 10.0.9 |
| Microsoft.EntityFrameworkCore.SqlServer | 10.0.8 | 10.0.9 |

## [6.0.3] - 18.06-2026

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion CSM Database Core/CSM Database Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net10.0</TargetFrameworks>
<RootNamespace>CSM_Database_Core</RootNamespace>
<PackageId>CSM.Database.Core</PackageId>
<Version>6.0.3</Version>
<Version>6.0.4</Version>
<Authors>Renato Urrea</Authors>
<Company>Cosmos (CSM)</Company>
<RepositoryUrl>https://github.com/Cosmos-CSM/csm_database</RepositoryUrl>
Expand Down
12 changes: 9 additions & 3 deletions CSM Database Core/Depots/Abstractions/Bases/DepotBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,15 @@ public async Task<UpdateOutput<TEntity>> Update(QueryInput<TEntity, UpdateInput<
TEntity? originalEntity = null;
IQueryable<TEntity> query = _dbSet;

originalEntity = await query
.Where(obj => obj.Id == updateEntity.Id)
.AsNoTracking()
IQueryable<TEntity> ogEntityQuery = query
.AsNoTrackingWithIdentityResolution()
.Where(obj => obj.Id == updateEntity.Id);

if (input.PostProcessor != null) {
ogEntityQuery = input.PostProcessor(ogEntityQuery);
}

originalEntity = await ogEntityQuery
.FirstOrDefaultAsync();

// --> When the update entity comes with ID, but there was no enitty stored with that ID, we check if creation is valid.
Expand Down
3 changes: 2 additions & 1 deletion DatabaseProxy/Entities/EntityProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ protected override void DesignEntity(EntityTypeBuilder etBuilder) {
etBuilder.Link<EntityProxy, EntityDependencyProxy>(
nameof(EntityDependencyProxy),
targetRef: nameof(EntityDependencyProxy.EntityProxies),
isAutoLoaded: true
isAutoLoaded: true,
deleteBehavior: Microsoft.EntityFrameworkCore.DeleteBehavior.Cascade
);
}
}

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,42 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace DatabaseProxy.Migrations
{
/// <inheritdoc />
public partial class IncludingCascadingDeletion : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_EntityProxies_EntityDependencyProxies_EntityDependencyProxy",
table: "EntityProxies");

migrationBuilder.AddForeignKey(
name: "FK_EntityProxies_EntityDependencyProxies_EntityDependencyProxy",
table: "EntityProxies",
column: "EntityDependencyProxy",
principalTable: "EntityDependencyProxies",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_EntityProxies_EntityDependencyProxies_EntityDependencyProxy",
table: "EntityProxies");

migrationBuilder.AddForeignKey(
name: "FK_EntityProxies_EntityDependencyProxies_EntityDependencyProxy",
table: "EntityProxies",
column: "EntityDependencyProxy",
principalTable: "EntityDependencyProxies",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
}
}
4 changes: 2 additions & 2 deletions DatabaseProxy/Migrations/DatabaseProxyModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.5")
.HasAnnotation("ProductVersion", "10.0.9")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
Expand Down Expand Up @@ -103,7 +103,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasOne("DatabaseProxy.Entities.EntityDependencyProxy", "EntityDependencyProxy")
.WithMany("EntityProxies")
.HasForeignKey("EntityDependencyProxyShadow")
.OnDelete(DeleteBehavior.Restrict);
.OnDelete(DeleteBehavior.Cascade);

b.Navigation("EntityDependencyProxy");
});
Expand Down
30 changes: 23 additions & 7 deletions Integration Tests/Tests/DepotBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,26 @@ protected override EntityProxy EntityFactory(string Entropy) {
public override async Task Update_Single_Success() {
//Expectation
EntityProxy testEntity = await Store(
new EntityProxy()
);
new EntityProxy {

}
);


EntityDependencyProxy dependency = await Store(
new EntityDependencyProxy()
);

EntityDependantProxy dependant = await Store(
new EntityDependantProxy()
);

await Store(
new EntityDependantProxy {
EntityProxy = testEntity
}
);

testEntity.EntityDependencyProxy = dependency;

UpdateOutput<EntityProxy> updateOutput = await _depot.Update(
Expand All @@ -62,17 +73,22 @@ public override async Task Update_Single_Success() {
}
);

Assert.NotNull(updateOutput.Original);
Assert.Empty(updateOutput.Original.EntityDependantProxies);
Assert.NotEmpty(updateOutput.Updated.EntityDependantProxies);
EntityProxy? ogEntity = updateOutput.Original;
EntityProxy updatedEntity = updateOutput.Updated;


Assert.NotNull(ogEntity);
Assert.Single(ogEntity.EntityDependantProxies);

Assert.NotEmpty(updatedEntity.EntityDependantProxies);

Assert.Contains(
updateOutput.Updated.EntityDependantProxies,
updatedEntity.EntityDependantProxies,
(dependantEntry) => dependantEntry.Id == dependant.Id
);
Assert.Equal(
dependency.Id,
updateOutput.Updated.EntityDependencyProxy.Id
updatedEntity.EntityDependencyProxy.Id
);
}
}
Loading