简体   繁体   中英

Add table dynamically in Entity framework in MVC

I have an MVC application in which i need to add the table dynamically ie 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?

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM