开发者

Why does Database First EF skip mapping some tables?

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?


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.


EF will ignore table without primary keys.


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.


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜