Add table dynamically in Entity framework in MVC

笑着哭i 提交于 2019-12-23 05:25:40

问题


I have an MVC application in which i need to add the table dynamically i.e table name is prepared dynamically. Is there any way we can check for the existence of a table and if not exist then add it in entity model.

If we can are able to create the table then how we can access the dynamically created table name using the object of entity model?


回答1:


No. If you want to use new table in EF you also need related entity (class), mapping and ObjectSet exposed in your context. Here you have some ideas what does it mean to use "dynamic" approach in EF.




回答2:


Why not create a KeyValuePair<MyTableProperties, List<MyObjects>> in the controller, or viewmodel for that matter, then make a strongly typed view and create the table in there depending of the value of the keyvaluepair object. Or are you talking about some other sort of table?



来源:https://stackoverflow.com/questions/5295554/add-table-dynamically-in-entity-framework-in-mvc

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