Search code examples
sql-serverdatabaseentity-framework-coremany-to-manyblazor

Accessing third table auto generated by entity framework when using many-to-many in models


When a many-to-many relation is defined within models, a third table is auto created by Entity framework. I am able to see this table within the database but I am not sure how I would access it's data. The third table is ApplicationUserProject defining a relationship between Projects and Users

How might access this table and it's data? Thanks in advance

Third generated table

enter image description here


Solution

  • In your particular case you do not need access to intermediate table.

    var query = context.Users
      .Where(u => u.Projects.Any(p => p.Id == projectId));