refactor: Beziehung zwischen „Object“ und „History“ hinzufügen.

This commit is contained in:
tekh 2025-08-01 15:08:30 +02:00
parent ec975a2bc3
commit 9d07b1e71c
5 changed files with 9 additions and 4 deletions

View File

@ -9,4 +9,6 @@ public class ObjectDto
public string? CmdCheckIn { get; set; }
public ObjectStateDto? State { get; set; }
public IEnumerable<ObjectStateHistDto> StateHistories { get; set; } = Array.Empty<ObjectStateHistDto>();
}

View File

@ -28,6 +28,5 @@ public class PObject
[ForeignKey("ObjStateId")]
public virtual PObjectState? State { get; set; }
[ForeignKey("ObjStateId")]
public virtual IEnumerable<PObjectStateHist>? StateHistory { get; set; } = Array.Empty<PObjectStateHist>();
public virtual IEnumerable<PObjectStateHist>? StateHistories { get; set; }
}

View File

@ -62,6 +62,4 @@ public class PObjectStateHist
[ForeignKey("StateId")]
public virtual State? State1 { get; set; }
public virtual IEnumerable<PControlsTF>? TFControls { get; set; }
}

View File

@ -37,5 +37,6 @@ public class PObjectRepository : IProfileObjRepository
.FromSqlRaw("SELECT * FROM [FNMWF_GET_PROFILE_OBJECTS] ({0}, {1})", userId, profileId)
.Include(obj => obj.State).ThenInclude(objState => objState != null ? objState.State1 : null)
.Include(obj => obj.State).ThenInclude(objState => objState != null ? objState.TFControls : null)
.Include(obj => obj.StateHistories).ThenInclude(hist => hist != null ? hist.State1 : null)
.ToListAsync(cancel);
}

View File

@ -52,6 +52,11 @@ public class WFDBContext : DbContext, IUserManagerDbContext
.HasForeignKey(control => control.ObjStateId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<PObject>()
.HasMany(p => p.StateHistories)
.WithOne()
.HasForeignKey(hist => hist.ObjectId);
base.OnModelCreating(modelBuilder);
}
}