EntityFramework 4.0: can you return different types depending on data in the database?
Posted
by user200341
on Stack Overflow
See other posts from Stack Overflow
or by user200341
Published on 2010-04-30T16:01:57Z
Indexed on
2010/04/30
16:27 UTC
Read the original article
Hit count: 217
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?
© Stack Overflow or respective owner