Why does Database First EF skip mapping some tables?

给你一囗甜甜゛ 提交于 2019-12-12 11:31:02

问题


I'm using Entity Framework 4 and with a Database First binding, and EF is not generating the entities for a few of my tables. I'm not getting any errors, and no matter how many times I select the tables to generate from the "Update Model from Database" popup menu on the design surface, the same tables are still missing from the model.

I get no errors in the wizard. They just don't get generated. Any clues?


回答1:


EF requires a primary key on the table. EF will not map tables for which it can't find or derive a primary key. If all columns are nullable, it can't assume a primary key. If one or more columns are not nullable, EF will evidently derive a primary key for the table.




回答2:


EF will ignore table without primary keys.




回答3:


Options I can think of:

  • Did you check the box next to those tables?

  • Did you previously add them, then delete their entities but keep the cache of the tables?

  • If so you can remove them from entity browser window and re-add them or manually add entities and define the table they map to in mappings window.

  • Perhaps tables were classified as relations instead of entities?

  • You can manually add the entities and choose the table they map to in mappings window.



回答4:


Actually, in my case, it doesn't work because I was using a hierarchyid field as a primary key and EF doesn't work with this field type, so, it didn't import the table, because a valid PK is required.




回答5:


A possibility is when you're using tables with some different field types, as hierarchy in SQL Server.




回答6:


Without Primary Key Tables where Skip Automatically on EF, OtherWise You Fix a Value as Not Null.



来源:https://stackoverflow.com/questions/6127757/why-does-database-first-ef-skip-mapping-some-tables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!