I have two classes, named Text
and Image
, which both inherit from the abstract class Item
. We've mapped this in a .edmx
file and have generated a database from there.
Now, whenever attempting to get a Text
or Image
from the database, I'm facing the following exception:
There are no EntitySets defined for the specified entity type 'ModelLibrary.Text'.
If 'ModelLibrary.Text' is a derived type, use the base type instead.
Parameter name: TEntity
I can't access or save Item
classes, since they are abstract classes and since they never contain the information associated with Text
or Image
classes.
The piece of code I'm using to try and access the data:
ProjectEntities context = new ProjectEntities(); //this inherits from ObjectContext and was generated by EF
var textRepo = new TextRepository(context);
var lstTexts = textRepo.GetAll();
foreach (var i in lstTexts)
{
Console.WriteLine(i.textTitle);
}
The textRepo
class is used for accessing and saving to the database. I get the exception on the constructor of the class the textRepo
inherits from (DataRepository)
:
protected DataRepository(ObjectContext context)
{
Context = context;
ObjectSet = Context.CreateObjectSet<T>();
}
I've already done some research on the exception, and have found this question: EF4 - custom ObjectContext and inheritance question
The answer to the question is actually something that is already supposed to happen (the making of an ObjectSet for the specific type). I just seem to get the exception at the line that is supposed to prevent the exception.
Now, I would like to know what could possibly be going wrong or what I am missing. Do I need to do something extra because of the inheritance? Mind you, I'm a little new with Entity Framework, so my apologies if I'm making a very obvious mistake here. If you need more information or code, feel free to ask.
EDIT: To be more specific on the exception, I get it on the ObjectSet = Context.CreateObjectSet<T>();
line. I can't add much to the piece of testing code, since I already get the exception at the constructor of the baseclass of the textRepo
class, namely the DataRepository
class.