In my current solution we're using the Entity Framework (4.0). I have model that is mapped to database. In that model i have an objectType named 'Document' which is mapped to the table 'Document'.
In my solution I have the object ExtDocument which inherits from Document. ExtDocument contains some extra properties which provide extra information but don't have any influence on the existing properties of the baseclass.
My main object used throughout the application is ExtDocument.
As it may happen we want to write a Document NOT ExtDocument. To our database
So i thought to use the following code:
dbContext.Document.AddObject((Document) doc);
or
dbContext.Document.AddObject((doc As Document));
But in both instances an exception is thrown that there is no mapping for ExtDocument. Is there a way to write the baseclass to the database without cloning the object first?
Note 1 ExtDocument is the only type that will be deriving from Document
Note 2 I've come across many questions with a slight reference to my problem but none supplied a solution or explained why i couldn't do it (without cloning).
examples:
metadata-information-not-found-while-using-ef4s-poco-template
ef-mapping-and-metadata-information-could-not-be-found-for-entitytype-error
map-derived-type-to-the-same-table-in-ef
how-to-properly-display-or-save-inheriting-classes-into-database-with-entity-fra <= Answerless
NOTE On Duplicate:
My issue does NOT occur upon instantiating a new class of the derived type. It only occurs upon saving to database