0

I have these entities:

    public class Project : Base
    {
        public string Name { get; set; }
        public string Description { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime? EndDate { get; set; }
        public ProjectStatus CurrentStatus { get; set; } = ProjectStatus.New;
        public List<StatusHistory>? StatusHistories { get; set; }
        public Team? Team { get; set; }
        public int? TeamId { get; set; }
        // public ProgressTrackerValue trackerValue { get; set; }
        public List<AttachedFile> AttachedFiles { get; set; }


    }
    public class Task : Base
    {
        public string Name { get; set; }
        public string  Description { get; set; }
        public DateTime? EstimatedDueDate { get; set; }
        public DateTime? ActualDueDate { get; set; } 
        public DateTime? StartDate { get; set; }
        public DateTime? EndDate { get; set; } // ?? End DATE same as ActualDueDate
        public TaskStatus CurrentStatus { get; set; } = TaskStatus.Draft;
        public int ProjectId { get; set; }
        public Project Project { get; set; }
        public List<StatusHistory> StatusHistories { get; set; }
        public TaskType TaskType { get; set; }
        public TaskPriority Priority { get; set; }
        public float ? DurationProgress { get; set; }
        public List<AttachedFile> AttachedFiles { get; set; }
    }
    public class Team : Base
    {
        public string TeamLeaderId { get; set; }
        public List<TeamMember>? TeamMembers { get; set; }
        public virtual Project Project { get; set; }

    }
    public class AttachedFile : Base
    {
        public string OriginalFileName { get; set; }
        public string FileName { get; set; }
        public string MimeType { get; set; }
        public string FileType { get; set; }
        public string OwnerType { get; set; }
        public int OwnerId {get; set;}
        public string FilePath { get; set; }
        public long FileSize { get; set; }
    }
    public class Comment : Base
    {
        public string Content { get; set; }
        public int? ParentCommentId { get; set; }
        public List<Comment>? Replies { get; private set; }
        public Task Task { get; set; }
        public int taskId { get; set; }
        public List<AttachedFile>? AttachedFiles { get; set; }
    }
    public class StatusHistory : Base
    {
        public string OwnerType { get; set; }
        public int OwnerId {get; set;}
        public string State { get; set; }
    }
    public class TaskEmployee : Base
    {

        public int TaskId { get; set; }
        public Task Task { get; set; }
        public string EmployeeId { get; set; }
    }
    public class TeamMember : Base
    {
        public string UserId { get; set; }
        
    }

What can I do to improve the above entities? Any suggestions.

Also there is UserId,EmployeeId,TeamLeaderId.... all of these supposed to be FK to IdentityUser but this project is isolated from Identity and i can't find a way to link them together. if there is a suggestion on how could I make such relationship in EFCore. (I could make relationship manually but I can't put navigation properties for Identity inside these entities thus not benefiting from EFCore).

Finally there is OwnerType, OwnerId, for example in the AttachedFile entity the attached file could be related to Project, Task, Comment. So I will store the type and id for them in these fields, the problem however that I will not benefit form EF Core functionality this way. For example: I must write SQL manually for every query.

currently the schema look like this:

enter image description here

Dale K
  • 25,246
  • 15
  • 42
  • 71
baha
  • 13
  • 2
  • 1
    What is the question here? – Sean Lange Jan 12 '23 at 21:08
  • I have to say that I really dislike databases that have id as the primary key name in every table. The reason I dislike it is because the column name changes when it is a foreign key. Is an EmployeeId not always an EmployeeId? Why should it be Id in some situations? – Sean Lange Jan 12 '23 at 21:11
  • @SeanLange last 2 paragraphs are the problems I'm facing right now. i need some suggestions to overcome those difficulties – baha Jan 12 '23 at 21:12
  • @SeanLange yeah naming convention here is pretty bad actually. but it could easily be changes since this project at early stage and there is a room for change and modifications. – baha Jan 12 '23 at 21:17
  • It's okay to separate the identity server database and business database. Just connect them logically using business logic without any real database constrain needed : https://stackoverflow.com/questions/57176368/separate-dbcontext-for-identity-and-business-operations-with-same-database-is#:~:text=It%20increases%20maintainability%20and%20is,not%20supposed%20to%20be%20mixed. – Fitri Halim Jan 13 '23 at 03:04

0 Answers0