是否可以在运行时加载EF元数据? [英] is it possible to load EF metadata at runtime?
问题描述
我想在运行时从数据库加载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?
推荐答案
是的,你可以这样做。
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屋!