I asked a question about ASP.NET MVC Generic Controller and this answer shows a controller like this:
public abstract class GenericController<T> where T : class { public virtual ActionResult Details(int id) { var model = _repository.Set<T>().Find(id); return View(model); } }
Which can be implemented like this.
public class FooController : GenericController<Foo> { }
Now when someone requests /Foo/Details/42, the entitiy is pulled from the _repository's
Set<Foo>()
, without having to write anything for that in theFooController
.
The way he explain that is good but think i want to develop a generic controller for product and customer where i will not use EF to load product & customer model rather use MS data access application block.
public abstract class GenericController<T>
where T : class
{
public virtual ActionResult Details(int id)
{
//var model = _repository.Set<T>().Find(id);
var model =customer.load(id);
or
var model =product.load(id);
return View(model);
}
}
So when request comes like /Customer/Details/42 or /product/Details/11
then generic controller's details method will call but how we can detect that request comes from which controller and accordingly instantiate right class to load right model.
If request comes for Customer then I need to load customer details from detail action method or if request comes for Product then I need to load Product details from detail action method of generic controller.
How do I use generics to get the dataset of type T
with the Entity Framework Data block?