How to use entity framework when Entities/Properties are only known at runtime?

[亡魂溺海] 提交于 2020-01-16 12:03:38

问题


I am using a mapping file that contains the Entity and the Column Names to perform the insert on so can this be done with entity framework ?

The alternative version is just to use inline SQL and write code like

sql = INSERT INTO " + someTable + etc....


回答1:


I don't think using Entity Framework (EF) will be a good fit for this project you're working on. One of the main benefits of using EF is the object graph; it takes care of recognizing new records, updated records and so on.

If you are working with dynamic objects and tables where you truly only know where your underlying data store is at runtime, then I would opt for using a generic database class with parameterized stored procedures.

Obviously the Entity Framework has gotten incredibly popular, but, there's nothing wrong with executing SQL the ol' fashioned way. EF doesn't have to be the only way you interact with your database.



来源:https://stackoverflow.com/questions/16864592/how-to-use-entity-framework-when-entities-properties-are-only-known-at-runtime

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