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:
parent
2fd64cb616
commit
7ed86f18d7
@ -17,7 +17,7 @@ public class ProfileControlsTF
|
||||
/// Validation should be enforced at the application level to ensure a value is provided.
|
||||
/// </summary>
|
||||
[Column("OBJ_STATE_ID", TypeName = "bigint")]
|
||||
public long? StateId { get; set; }
|
||||
public long? ObjStateId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Although this field is marked as <c>nullable</c> in the database schema to allow
|
||||
@ -97,6 +97,6 @@ public class ProfileControlsTF
|
||||
[Column("ADDED_WHEN", TypeName = "datetime")]
|
||||
public DateTime AddedWhen { get; set; }
|
||||
|
||||
[ForeignKey("StateId")]
|
||||
[ForeignKey("ObjStateId")]
|
||||
public virtual ProfileObjState? State { get; set; }
|
||||
}
|
||||
@ -79,9 +79,11 @@ public class ProfileObjState
|
||||
[Column("CHANGED_WHEN", TypeName = "datetime")]
|
||||
public DateTime? ChangedWhen { get; set; }
|
||||
|
||||
[ForeignKey("StateId")]
|
||||
[ForeignKey("ObjStateId")]
|
||||
public virtual State? State1 { get; set; }
|
||||
|
||||
public IEnumerable<ProfileControlsTF> TFControls { get; set; } = Array.Empty<ProfileControlsTF>();
|
||||
|
||||
public IEnumerable<string?> ToList() => new List<string?>
|
||||
{
|
||||
State1?.IntlState, State2, State3, State4
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user