'Generic' ViewModel

Posted by Ian MacPherson on Stack Overflow See other posts from Stack Overflow or by Ian MacPherson
Published on 2010-01-18T17:31:30Z Indexed on 2010/04/06 22:23 UTC
Read the original article Hit count: 403

Using EF 4, I have several subtypes of a 'Business' entity (customers, suppliers, haulage companies etc). They DO need to be subtypes. I am building a general viewmodel which calls into a service from which a generic repository is accessed.

As I have 4 subtypes, it would be good to have a 'generic' viewmodel used for all of these. Problem is of course is that I have to call a specific type into my generic repository, for example:

BusinessToRetrieve = _repository
    .LoadEntity<Customer>(o => o.CustomerID == customerID);

It would be good to be able to call <SomethingElse>, somethingElse being one or other of the subtypes), otherwise I shall have to create 4 near identical viemodels, which seems a waste of course! The subtype entity name is available to the viewmodel but I've been unable to figure out how to make the above call convert this into a type. An issue with achieving what I want is that presumably the lambda expression being passed in wouldn't be able to resolve on a 'generic' call ?

© Stack Overflow or respective owner

Related posts about entity-framework

Related posts about entity-framework-4