EntityFramework Fluent One to Many relation with static table

David Thielen 3,216 Reputation points
2023-03-09T23:43:20.3133333+00:00

This exact question has been asked (5 years ago), but the answer there doesn't compile. So I'm asking again.

I have a class that is a set of skills, similar to the tags in a SO question, where users are assigned a number of skills. The skills table has a row for each skill and will be static (occasionally an additional skill may be added).

Each user is assigned a collection of 0..N skills. And there are 2 collections, the self-certified skills and the passing a test certified skills.

The user class includes:

public class User
{
    public ICollection<Skill> SelfIdentifiedSkills { get; set; }
    public ICollection<Skill> CertifiedSkills { get; set; }
    // ...
}

And the skill class is:

public class Skill
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
}

What do I need to add to OnModelCreating() to make this work. Both for handling the fact that the Skill records are static and to handle that both collections are a collection against the same table and so I need to avoid naming collisions.

thanks - dave

Developer technologies | .NET | Entity Framework Core
0 comments No comments
{count} votes

Answer accepted by question author
  1. Jack J Jun 25,316 Reputation points
    2023-03-13T02:36:54.65+00:00

    @David Thielen, Welcome to Microsoft Q&A, based on my test, I also find that the code could not complied. Because the code is used in EF instead of EF Core. After searching many docs, I find that you need to re-design your model. I find the following answer may be helpful for your question and you could have a check.

    https://stackoverflow.com/a/51756430

    Best Regards,

    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.