C
C#10mo ago
SWEETPONY

How to create entity correctly? [EF CORE]

I have a following model:
public sealed record WorkingTask: BaseEntity
{
public required string Identity {get;set;}
public IReadOnlyList<RequiredQualifications>? RequiredQualifications { get; init; }
}
public sealed record WorkingTask: BaseEntity
{
public required string Identity {get;set;}
public IReadOnlyList<RequiredQualifications>? RequiredQualifications { get; init; }
}
public class RequiredQualifications
{
public string? QualificationId { get; set; }
public byte? Degree { get; set; }
}
public class RequiredQualifications
{
public string? QualificationId { get; set; }
public byte? Degree { get; set; }
}
how to store it correctly in database? should it be 1 - 1 or many-many? how to configure it in ef core? maybe I should add Id property to
RequiredQualifications
RequiredQualifications
? for example:
public class RequiredQualifications
{
public Guid WorkingTaskId {get;set;}
public string? QualificationId { get; set; }
public byte? Degree { get; set; }
}
public class RequiredQualifications
{
public Guid WorkingTaskId {get;set;}
public string? QualificationId { get; set; }
public byte? Degree { get; set; }
}
2 Replies
SWEETPONY
SWEETPONYOP10mo ago
also what if I want to do smth like that in future:
public sealed record WorkingTask: BaseEntity
{
public required string Identity {get;set;}
public IReadOnlyList<RequiredQualifications>? RequiredQualifications { get; init; }
}
public sealed record WorkingTask: BaseEntity
{
public required string Identity {get;set;}
public IReadOnlyList<RequiredQualifications>? RequiredQualifications { get; init; }
}
public sealed record Function: BaseEntity
{
public required string Identity {get;set;}
public IReadOnlyList<RequiredQualifications>? RequiredQualifications { get; init; }
}
public sealed record Function: BaseEntity
{
public required string Identity {get;set;}
public IReadOnlyList<RequiredQualifications>? RequiredQualifications { get; init; }
}
public Guid WorkingTaskId {get;set;} in RequiredQualifications looks bad
Jimmacle
Jimmacle10mo ago
it looks like many to many to me, assuming you can have many tasks that pick from the same set of qualifications in which case you use a join table/entity in EF core you can model it by giving the task a collection of qualifications and the qualifications a collection of tasks
Want results from more Discord servers?
Add your server