I've 'Googled' and 'Binged' for all the Web trying开发者_如何学运维 to solve this problem... I had no success so I returned to ADO.NET 4.x to continue my work
I have a program in which the user can select and open any database... The tables, views, stored procs, etc. of the select database are shown in a tree so the user can click a node and view/edit data in a grid.
After struggling a few times with EF4 (DB First, Model First, Code First, etc.) I cant find a way to at runtime generate the entities for the user selected database...
Anyone can provide extra Info... maybe sample code ???
You can't. Entity Framework (like any other ORM) is used to map a data model to a logical model. If there's no mapping (and no logical model), there's no Entity Framework.
ADO is the way to go in this case.
After some questionning, it is possible to do it, but it involves crazy steps.
To do it, you'd have to generate the edmx xml from the informations you'll get by querying the master database, from this xml generate the classes (data context and entities) at runtime, load them in your AppDomain through code dom, and then you could use this dynamically generated data context through Entity Framework.
In one sentence : for this kind of scenario where you data model is totally unknown and changing, stick to good ol' ADO.NET. It's tailored for this.
精彩评论