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:
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user