EF Mapping and metadata information could not be found for EntityType Error

后端 未结 13 1636
萌比男神i
萌比男神i 2020-12-05 09:42

I have encountered an exception when I use Entity Framework 4.0 RC. My Entity Framework model is encapsulated in a private assembly who\'s name is Procurement.EFDataProvider

相关标签:
13条回答
  • 2020-12-05 10:05

    Another possible issue is, if you are using code-first and your entity type is defined in a separate assembly to where the context is define and you haven't added any custom mappings to the OnModelCreating(DbModelBuild modelBuilder) method, then EF seems to ignore the data annotations.

    Solution:

    Add modelBuilder.Entity<YourEntityType>(); to the OnModelCreating(DbModelBuild modelBuilder) method.

    Related post.

    0 讨论(0)
  • 2020-12-05 10:08

    I have also seen it when the connection string is not specified in the config file.

    0 讨论(0)
  • 2020-12-05 10:11

    My problem was I had edited the T4 template to exclude the replication field named "msrepl_tran_version". This caused the database to not match the generated classes which can causes this error message. Just make sure your database and classes match.

    0 讨论(0)
  • 2020-12-05 10:12

    Just check the property spelling with the model

    0 讨论(0)
  • 2020-12-05 10:17

    Not directly related to the above, but if you get this error message and you have mixed a POCO and a regular model: bad idea!

    See also the comment from JRoppert at EF4 POCO (not using T4): Mapping and metadata information could not be found for EntityType (thanks JRoppert!)

    0 讨论(0)
  • 2020-12-05 10:19

    For anyone else dealing with the error, I think it's worth mentioning some scenarios that I've found that cause this (extremely unhelpful) error:

    • Misspelled properties (case-sensitive!)
    • Properties missing in the POCO class
    • Type mismatches between the POCO and entity-type (e.g., int instead of long)
    • Enums in the POCO (EF doesn't support enums right now as I understand)

    There might be other causes as well.

    HTH

    0 讨论(0)
提交回复
热议问题