0

I'm getting mapping errors when running a database first project. I know where I'm supposed to fix them but it's been a while since I've done database first and I can't figure out how to fix it. The more I seem to change things, the more goes wrong.

Any links to tutorials, guides or blog posts about these mapping problems or solutions are welcome. I can't find anything via Google that explains what I should change.

The type 'Paycento_Models.Domain.Campaign' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The type 'Paycento_Models.Domain.Campaign' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject.

enter image description here


enter image description here

Reinard
  • 3,624
  • 10
  • 43
  • 61
  • have you done an update in the edmx file (update from database)? Also can you post the mapping of campaing, not Page? – daryal Apr 02 '12 at 08:31
  • @daryal, It's not generated from a database, I started from a written ERD. *Added in Campaign mapping screenshot – Reinard Apr 02 '12 at 08:36
  • In the page mapping Campaign_Id is not mapped, you should map it to the related columns. – daryal Apr 02 '12 at 08:39
  • @daryal, it only offers me to map it to Id, Logo, LogoAlt, Title, description, Footer, CSS :s – Reinard Apr 02 '12 at 08:47
  • Can you check whether the Page table has a foreign key of Campaign? – daryal Apr 02 '12 at 08:50
  • The relationship seems to be fine. I got the same problem with the RedeemPage -> Field relation :s – Reinard Apr 02 '12 at 09:00
  • https://weblogs.asp.net/manavi/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-3-table-per-concrete-type-tpc-and-choosing-strategy-guidelines – Nikhil Agrawal Dec 27 '16 at 10:08

1 Answers1

0

This problem arises because your model is not aware of your changes in the database. In order to resolve this problem, right click your model and select update from database. Your model somehow does not have the right storage model in the xml.

daryal
  • 14,643
  • 4
  • 38
  • 54
  • I don't have a database, I have an ERD on paper which I copied to VS. – Reinard Apr 02 '12 at 09:30
  • I don't think that just copying ERD on paper is sufficient. edmx file uses storage, conceptual and mapping related xml elements. just open open edmx file using an xml editor and investigate. As far as I know, EF does not work directly without any database defined if you are not using code first. In the edmx xml, possibly some storage nodes do not exists, as a result some mappings are not defined. This is the root of your problem. Nothing directly related to EF. – daryal Apr 02 '12 at 10:16