EntityFramework 4.0: Can you return different types based on the data in the database?


I have a Media table in the database. I also have an IMedia interface.

I have two different media types that implements the same interface:

1) AudioMedia
2) PictureMedia

What I wonder here, is if I can use EntityFramework (I'm using an EDMX file but I have my models in a separate library, with automatic code generation turned off), and depending on the data in the database, select what type to get (AutioMedia or PictureMedia).

Since they are both implementing the same interface (could be changed to an abstract class if needed I suppose), I'm thinking that somewhere along the way you could specify what class it should be.

I should perhaps point out that I have a class that inherits from ObjectContext to access the objects. Perhaps there is something that that can be done?

Do you have a common ID field?

Take a look at




Changing it to an Abstract base class would almost certainly make it easier to model using Entity Framework.