title: How do I prevent foreign keys from being loaded onto my DataGrid?
body: <p>Right now, I'm taking all the information under my tables and binding it to my DataGrids. </p>
  
  <p>However, this leaves my foreign key visible on the DataGrid which I don't want. Also, I don't an Id column visible too. </p>
  
  <p>How can I just select certain columns from my database and bind it onto my DataGrid instead of binding all my data onto my DataGrid?</p>
  
  <p>I think I just have to write a query but seems like it's not working. Perhaps it's because I'm still new to Entity Framework. </p>
  
  <p>Here's how I'm storing my data into db...: </p>
  
  <pre><code> using (var db = new DMIDataContext())
  {LotInformation newLot = new LotInformation();
  
          newLot.Id = lot.Id;
          newLot.lot_number = lot.lot_number;
          newLot.exp_date = lot.exp_date;
  
    foreach (Components comp in lot.Components)
          {
  
                     newLot.Components.Add(comp);
  
           }
           ComponentsList = newLot.Components;
  
    foreach (Families fam in lot.Families)
          {
  
                     newLot.Families.Add(fam);
  
           }
           Families = newLot.Families; 
  
           db.LotInformation.Add(newLot);
           db.SaveChanges();
  </code></pre>
  
  <p>Here's how I'm grabbing db data: </p>
  
  <pre><code> public static void ReadLot(string lotNumber)
      {
  
          using (var db = new DMIDataContext())
          {
              try
              {
                  LotInformation lotInfo = db.LotInformation.FirstOrDefault(r =&gt; r.lot_number.Equals(lotNumber));
              }
              catch (InvalidOperationException e)
              {
  
              }
          }
      }
  </code></pre>
  
  <p>I think the problem lies in the above query... I tried using FirstOrDefault().Select() but I guess I can't do a select Select after FirstOrDefault... not sure why. </p>
  
  <p>The way the foreign keys are set up in my class is: </p>
  
  <pre><code>    public virtual int LotInformationId { get;  set; }
      public virtual LotInformation LotInformation { get; set; }
  </code></pre>
  
  <p>But I don't want that data binding to my dataGrid... </p>
  
  <p>Hope this is clear. Please ask me if you have any questions. </p>
  
  <p>Thanks! </p>