I have 2 projects, one that deal with the Data Access and it uses entity framework and POCO objects to do it. and the second project reference that DAL Project to access the database.
In my second project i need to inherit from a POCO class and provide some default values for some properties and other stuff, at the end i want to add this class or “its base class” to the object context of the entity framework.
But everytime i do i get an exception that says, “Mapping and metadata information could not be found for EntityType ‘MyInheritedClass'”
Is there anyway to work around this without using partial class, or editing the project that has the Data Access Layer.
Thanks
Unfortunately no. Current versions of EF are not able to work with derived classes if they are not mapped. If you map a class you must use that class type for data retrieval and persistence – EF will never get you instance of non mapped derived type and it will also not accept derived type because EF doesn’t know the type.
If you want to use derived class you must define it directly in Data Access library and that class must be part of mapped inheritance (and in such case the inheritance will be reflected in your database). Otherwise don’t use inherited class and move all additional properties and logic directly to original POCO (which is btw. supposed usage).