开发者

Is it possible to get underlying table name from the model in Entity Framework 4

In order to avoid magic strings when running the ExecuteStore command is it possible to get underlying table name [and columns] from the model in E开发者_运维技巧ntity Framework 4

Liam


I can't tell you if there is, but the best shot would be to dive into the metadata of the context.

This might help you, it is a documentation about the metadata of the EF. If you can't find it in the metadata, you are most likely out of luck.

Edit according to this (bottom of the page):

I have also been trying to query the mapping metadata. I wanted to find the metadata which describes how tables and entities are mapped and which stored procedures are mapped to entities. I was not able to find the metadata I needed via the MetadataWorkSpace. Afterwards Danny Simmons from Microsoft did let me know that this mapping metadata is not available publically and that it is something they have to do in a future release of the Entity Framework.

It seems to be impossible at the moment as this information is not publically avaiable; however, this is from 2008, so it might have changed in the meantime.


I'll quote Rowan Miller ...

Hi,

Unfortunately in CT4 there is no public surface that allows you to find what the table name is for a given entity type. This is actually a limitation of EF in general as we don't have a public API to access the mapping section of the model. This is something we are working to improve at the moment.

~Rowan

CTP 4 being a pre-production update to EF4, in this case. My only suggestion for bypassing this, evil as it is, is for you to try parsing the XML in the model directly, and strip the table names from that. Very evil, but it should be doable. Remember though that models can relate to multiple tables, or views, or combinations.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜