I have a scenario where I have 3 types of products in a database and all products have their own separate tables (e.g. Product1
, Product2
and Product3
). Almost all of the product tables have the same schema. I have the requirement to get separate types of products in different tables.
I currently have 3 methods to get the products, one for each product type:
public List<Product1> GetProduct1Data() {
//....
context.Product1.Where(..).Tolist();
}
public List<Product2> GetProduct2Data() {
//....
context.Product2.Where(..).Tolist();
}
public List<Product3> GetProduct3Data() {
//....
context.Product3.Where(..).Tolist();
}
While calling products I have a WebApi method which accepts product type and calls the respective methods:
public IHttpActionResult GetProducts(ProductType product)
{
///....
// Ii have to call repositories according to product parameter
}
Does Entity Framework have any way that I can select a table with only one method?
See Question&Answers more detail:os