是否可以在运行时加载EF元数据? [英] is it possible to load EF metadata at runtime?

查看:91
本文介绍了是否可以在运行时加载EF元数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行时从数据库加载EF元数据。这种情况是否可行?首先从数据库获取数据,然后写入.ssdl,.msl和.csdl文件听起来不错。但是如何告诉EF使用我已经加载的?我需要编译它吗?

I want to load EF metadata from database at runtime. Is that scenario possible? First get the data from database, then write it to .ssdl, .msl and .csdl files sounds ok. But how to tell EF to use what I've loaded? Do I need to compile it or something like that?

推荐答案

是的,你可以这样做。

使用 MetadataWorkspace http://msdn.microsoft.com/en-us/library/cc679683( v = VS.100).aspxrel =nofollow noreferrer>构造函数,它将这些文件

New up a MetadataWorkspace using the constructor which takes these files.

然后你可以新建一个 EntityConnection MetadataWorkspace 传递给重载的构造函数,最后新增 ObjectContext

Then you can new up an EntityConnection passing the MetadataWorkspace to the overloaded constructor, and finally new the ObjectContext passing that.

所有这一切,我想知道这是否是您问题的最佳方法。

With all that said, I wonder if this is the best approach to your problem.

这篇关于是否可以在运行时加载EF元数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆