连接到实体模型使用反射 [英] Connect to an Entity Model using Reflection
问题描述
我在写一个小程序,从程序集和查询对他们加载实体数据模型。
I'm writing a little utility to load Entity Data Models from an assembly and query against them.
我使用反射来加载一个派生<试过code>的ObjectContext ,但的ObjectContext
不会从 MarshalByRefObject的
得出这样我就可以()(根据例外,我得到的。)'T参数传递给构造与 Activator.CreateInstance
I've tried using Reflection to load a derived ObjectContext
, but ObjectContext
doesn't derive from MarshalByRefObject
so I can't pass parameters to the constructor with Activator.CreateInstance()
(according to the exception I get.)
是否有可能加载实体模型中定义和使用反射,晚绑定到EDM存储在外部组件以及执行查询反对它,如果你提供了一个有效的连接字符串?
推荐答案
我相信ObjectContext.Metadataworkspace.LoadFromAssembly()就是你想找的:
I believe ObjectContext.Metadataworkspace.LoadFromAssembly() is what your looking for:
http://msdn.microsoft.com/en-us/library/bb495513.aspx
这篇关于连接到实体模型使用反射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!