Refactor ProfileControlsTF and ProfileObjState relationships

Updated property names and foreign key references in
ProfileControlsTF and ProfileObjState classes to improve
database relationship integrity. Added TFControls collection
to ProfileObjState and modified queries in ProfileObjRepository
to include related entities. Established relationships in
WFDBContext with cascade delete behavior.
This commit is contained in:
2025-08-01 10:54:08 +02:00
parent 2fd64cb616
commit 7ed86f18d7
4 changed files with 14 additions and 3 deletions

View File

@@ -36,5 +36,6 @@ public class ProfileObjRepository : IProfileObjRepository
=> await _context.Objects
.FromSqlRaw("SELECT * FROM [FNMWF_GET_PROFILE_OBJECTS] ({0}, {1})", userId, profileId)
.Include(obj => obj.States).ThenInclude(objState => objState != null ? objState.State1 : null)
.Include(obj => obj.States).ThenInclude(objState => objState != null ? objState.TFControls : null)
.ToListAsync(cancel);
}

View File

@@ -2,6 +2,7 @@
using DigitalData.UserManager.Infrastructure;
using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.SqlServer.Query.Internal;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Infrastructure;
@@ -45,6 +46,13 @@ public class WFDBContext : DbContext, IUserManagerDbContext
//configure model builder for user manager tables
modelBuilder.ConfigureUserManager();
modelBuilder.Entity<ProfileObjState>()
.HasMany(pos => pos.ControlsTF)
.WithOne()
.HasForeignKey(pctf => pctf.ObjStateId)
.HasPrincipalKey(pos => pos.Id)
.OnDelete(DeleteBehavior.Cascade);
base.OnModelCreating(modelBuilder);
}
}