title: Linq to SQL: Populating an extended generated class in a Linq Query
body: <p>Ok so, I have a class that's generated when I created the Linq to SQL connection.</p>
  
  <p>It basically looks like this:</p>
  
  <pre>
  <code>
      public partial class Product
      {
          public string Name { get; set; }
          public string Description { get; set; }
      }
  </code>
  </pre>
  
  <p>I extended it by adding another property, like this:</p>
  
  <pre><code>
      public partial class Product
      {
          public string Category { get; set; }    
      }
  </code></pre>  
  
  <p>Now I have a Linq query to get the product details, like this:</p>
  
  <pre><code>
      public List GetProducts()
      {
          using(MyDataContext dc = new MyDataContext())
          {
              var products = from p in dc.Products
                             select p;
          }
      }
  </code></pre>
  
  <p>The new field I added(Category) can be retrieved in the Linq query by using "p.Category.Description".  </p>
  
  <p>So my question is, which is that best way to populate the Product class including the new Category property.</p>
  
  <p>I'd prefer if there was a way to automatically populate the generated portion of the Product class by using the data in the Linq query "select p".</p>
  
  <p>I've also thought of creating a constructor on my partial class that accepts the product (select P) and the Category(select p.Category.Description)</p>
  
  <p>Doing something like this:</p>
  
  <pre><code>
      // Linq query calling the constructor
      var products = from p in dc.Products
                     select new Product(p, p.Category.Description)
  
      // Product Constructor in my extended partial class
      public Product(Product p, string CategoryDescription)
      {
          this = p; // there must be a way to do something like this
          Category = CategoryDescription;
      }
  </code></pre>
  
  <p>But is there a way to do this without having to list every property in the Product class and set each of them individually ??</p>