title: Database First with Bridge Table, How to Keep It Out of Model
body: <p>I am trying to find out how I can make a bridge table entity, used for a many to many relationship, transparent to my model.  I am using EF <strong>Database First</strong>.</p>
  
  <p><strong>Tables in question</strong>...(simplified)</p>
  
  <pre><code>Report
  - ReportId INT PK
  - ReportName VARCHAR(50)
  
  Group
  - GroupId INT PK
  - GroupName VARCHAR(50)
  
  ReportGroup
   - ReportId INT PK
   - GroupId INT PK
  </code></pre>
  
  <p><strong>Current Class Structure</strong>...(simplified)</p>
  
  <pre><code>public class Report
  {
       public int ReportId { get; set; }
       public string ReportName { get; set; }
       public IList&lt;ReportGroup&gt; ReportGroups { get; set; }
  }
  
  public class Group
  {
       public int GroupId { get; set; }
       public string GroupName { get; set; }
       public IList&lt;ReportGroup&gt; ReportGroups { get; set; }
  }
  
  public class ReportGroup
  {
       public int ReportId { get; set; }
       public Report Report { get; set; }
       public int GroupId { get; set; }
       public Group Group { get; set; }
  }
  </code></pre>
  
  <p>Using the above, to get the groups that a Report belongs to requires something like this...</p>
  
  <pre><code>// Getting a report's groups
  var report = this.ReportService.GetReportById(123456);
  var groups = report.ReportGroups.Select(x =&gt; x.Group).ToList();
  </code></pre>
  
  <p>That's not exactly something I want to be using throughout my application.  Ideally, I'd like the bridge table and Entity (ReportGroup) to be transparent, allowing me to work with the entities like this...</p>
  
  <pre><code>// Getting a report's groups
  var report = this.ReportService.GetReportById(123456);
  var groups = report.Groups;
  
  // Getting a group's reports
  var group = this.ReportService.GetGroupById(1);
  var reports = group.Reports;
  </code></pre>
  
  <p>So my question is whether this is possible with EF <strong>Database First</strong>, and if so, how do I wire this up correctly using the Fluent API in <strong>OnModelCreating</strong>().  </p>
  
  <p>Thanks in advance for the help. </p>