简体   繁体   English

如何使用实体框架4打开未知结构数据库

[英]How to open unknown structure database with entity framework 4

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 我已经为尝试解决此问题的所有网络使用了“ Googled”和“ Binged” ...我没有成功,所以我回到ADO.NET 4.x继续工作

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. 我有一个程序,用户可以在其中选择和打开任何数据库...选择数据库的表,视图,存储的proc等显示在树中,以便用户可以单击节点并在其中查看/编辑数据。网格。

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... 在使用EF4(数据库优先,模型优先,代码优先等)苦苦挣扎几次之后,我找不到在运行时为用户选择的数据库生成实体的方法。

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. 实体框架(与任何其他ORM一样)用于将数据模型映射到逻辑模型。 If there's no mapping (and no logical model), there's no Entity Framework. 如果没有映射(也没有逻辑模型),那么就没有实体框架。

ADO is the way to go in this case. 在这种情况下,ADO是可行的方法。

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. 为此,您必须根据查询主数据库所获得的信息来生成edmx xml,并在运行时从该xml中生成类(数据上下文和实体),并通过代码dom将它们加载到AppDomain中,然后您可以通过实体框架使用此动态生成的数据上下文。

In one sentence : for this kind of scenario where you data model is totally unknown and changing, stick to good ol' ADO.NET. 一句话:对于这种情况,您的数据模型是完全未知和不断变化的,请坚持使用ADO.NET。 It's tailored for this. 为此而量身定做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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