Ok, so I have an abstract class called Product. I have 3 tables called Items, Kits, and Packages that implement Product. Product has a public property that exposes the object's primary key.
That said I have a form where I pass a product. I would would like to pull that product out of a fresh datacontext without having to write a big switch reflecting it's type to get its proper table.
I wanted to do something like this but the cast bit won't accept foo.
public BuilderInclusionsForm(Product p) : this()
{
Type foo = p.GetType();
product = db2.GetTable(p.GetType()).Cast<foo>().SingleOrDefault(a =>
a.ProductID == p.ProductID);
or this:
public BuilderInclusionsForm(Product p) : this()
{
Type foo = p.GetType();
product = db2.GetTable(p.GetType()).OfType<foo>().SingleOrDefault(a =>
a.ProductID == p.ProductID);