Ok so, I have a class that's generated when I created the Linq to SQL connection.
It basically looks like this:
public partial class Product
{
public string Name { get; set; }
public string Description { get; set; }
}
I extended it by adding another property, like this:
public partial class Product
{
public string Category { get; set; }
}
Now I have a Linq query to get the product details, like this:
public List GetProducts()
{
using(MyDataContext dc = new MyDataContext())
{
var products = from p in dc.Products
select p;
}
}
The new field I added(Category) can be retrieved in the Linq query by using "p.Category.Description".
So my question is, which is that best way to populate the Product class including the new Category property.
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".
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)
Doing something like this:
// 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;
}
But is there a way to do this without having to list every property in the Product class and set each of them individually ??