title: Lookup for an Entity Column ID
body: <p>I have an Entity Framework Core project that uses generic repositories and UnitOfWork and is working as expected.</p>
  <p>The database is one to many and related by IDs.</p>
  <p>The <code>RTCTrials</code> entity contains a FK <code>CourseID</code> related to <code>RTCCourses</code> PK. When loading trials I am trying to get the course name in the datagrid and only achieved by using a union. Is this inefficient and a simpler approach. Ideally I would add a dropdownlist column populated with <code>RTCCourses</code> in the trials grid template and the <code>CourseID</code> in the trials table would select the correct id and show the <code>ValueMember</code> course name.</p>
  <p>This is what the current method looks like:</p>
  <pre><code>using (var context = new RTCContext())
  {
      var factory = new EntityFrameworkUnitOfWorkFactory(context);
      var unit = factory.Create();
  
      var festivals = unit.RTCFestivals.All().ToList();
      var trials = unit.RTCTrials.All().ToList();
      var courses = unit.RTCCourses.All().ToList();
  
      var trialcourses = trials.Join(courses, courses =&gt; courses.CourseID, trials =&gt; trials.CourseID, (trials, courses) =&gt; new
              {
                  TrialID = trials.TrialID,
                  FestivalID = trials.FestivalID,
                  CourseID = trials.CourseID,
                  Trial = trials.Trial,
                  Course = courses.CourseName,
                  TrialGrade = trials.TrialGrade,
                  TrialDistance = trials.TrialDistance,
                  TrialAge = trials.TrialAge,
                  TrialHurdles = trials.TrialHurdles,
                  TrialAllowances = trials.TrialAllowances,
                  TrialMonth = trials.TrialMonth,
                  TrialActualDate = trials.TrialActualDate,
                  TrialActualTime = trials.TrialActualTime,
                  TrialRaceCard = trials.TrialRaceCard,
                  TrialQualifiers = trials.TrialQualifiers
              }).ToList();
  
      this.radGridViewFestivalDestinations.DataSource = festivals;
      this.radGridViewFestivalDestinations.Templates[0].DataSource = trialcourses;
  
      foreach (GridViewDataColumn column in radGridViewFestivalDestinations.MasterTemplate.Columns)
      {
          column.BestFit();
      }
  
      foreach (GridViewDataColumn column in radGridViewFestivalDestinations.Templates[0].Columns)
      {
          column.BestFit();
      }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/zNuR5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zNuR5.png" alt="Entity Diagram" /></a></p>
  <p>RTCTrial Entity</p>
  <pre><code>public partial class RTCTrial {
  
      public RTCTrial()
      {
          this.RTCResults = new List&lt;RTCResult&gt;();
          this.RTCWeathers = new List&lt;RTCWeather&gt;();
          OnCreated();
      }
  
      public virtual int TrialID { get; set; }
  
      public virtual int FestivalID { get; set; }
  
      public virtual int CourseID { get; set; }
  
      public virtual string Trial { get; set; }
  
      public virtual string TrialGrade { get; set; }
  
      public virtual string TrialDistance { get; set; }
  
      public virtual string TrialAge { get; set; }
  
      public virtual int? TrialHurdles { get; set; }
  
      public virtual string TrialAllowances { get; set; }
  
      public virtual string TrialMonth { get; set; }
  
      public virtual DateTime? TrialActualDate { get; set; }
  
      public virtual TimeSpan? TrialActualTime { get; set; }
  
      public virtual string TrialRaceCard { get; set; }
  
      public virtual int TrialQualifiers { get; set; }
  
      public virtual RTCCourse RTCCourse { get; set; }
  
      public virtual RTCFestival RTCFestival { get; set; }
  
      public virtual IList&lt;RTCResult&gt; RTCResults { get; set; }
  
      public virtual IList&lt;RTCWeather&gt; RTCWeathers { get; set; }
  
      #region Extensibility Method Definitions
  
      partial void OnCreated();
  
      #endregion
  }
  </code></pre>
  <p>RTCCourse Entity</p>
  <pre><code>public partial class RTCCourse {
  
      public RTCCourse()
      {
          this.RTCTrials = new List&lt;RTCTrial&gt;();
          OnCreated();
      }
  
      public virtual int CourseID { get; set; }
  
      public virtual string CourseName { get; set; }
  
      public virtual string CourseCountry { get; set; }
  
      public virtual string CourseDirection { get; set; }
  
      public virtual string CourseCharacteristics { get; set; }
  
      public virtual string CourseAlternateName { get; set; }
  
      public virtual double CourseLat { get; set; }
  
      public virtual double CourseLong { get; set; }
  
      public virtual IList&lt;RTCTrial&gt; RTCTrials { get; set; }
  
      #region Extensibility Method Definitions
  
      partial void OnCreated();
  
      #endregion
  }
  </code></pre>
  <p>Regards, Neil</p>