实体框架连接元数据提取
我正在使用 EntityFramework POCO 适配器,并且由于 microsoft 提供的元数据访问权限存在限制,因此我手动从 xml 中提取所需的信息。唯一的问题是我想要加载 ssdl、msl、csdl 文件名,而不必直接检查 app.config 中的连接字符串节点。 简而言之,我可以在 ObjectContext/EntityConnection 的哪里访问这些文件名? 最坏的情况是我需要从 EntityConnection 对象获取连接名称,然后从 app.config 加载它并解析字符串本身并自己提取文件名。 (但我显然不想这样做)。 谢谢
I am using the EntityFramework POCO adapter and since there are limitations to what microsoft gives access to with regards to the meta data, i am manually extracting the information i need out of the xml. The only problem is i want to get the ssdl, msl, csdl file names to load without having to directly check for the connection string node in app.config.
In short where in the ObjectContext/EntityConnection can i get access to these file names?
Worst case scenario i need to get the connection name from the EntityConnection object then load this from app.config and parse the string itself and extract the filenames myself. (But i obviously don't want to do that).
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可以想到两种使用反射的方法:
深入 EntityConnection。连接字符串应该作为私有变量存在于某处。
默认情况下,EDM 元数据文件作为资源嵌入到程序集中。您应该能够反映包含 EDM 的程序集并直接提取文件。在包含 EDM 的程序集中使用 Reflector,您应该会看到嵌入的 msl、ssdl、csdl。
我认为选项 2 总体上更稳健。
I can think of two ways to use reflection here:
Dig into the EntityConnection. The connection string should be in there somewhere as a private variable.
The EDM metadata files are embedded in the assembly as resources by default. You should be able to reflect the assembly that contains the EDM and pull the files out directly. Use Reflector on your assembly that contains your EDM and you should see the embedded msl, ssdl, an csdl.
I think option 2 is more robust overall.
您是否查看过 ObjectContext.MetadataWorkspace?它不是最容易使用的图书馆,但我能够获得我需要的所有信息。
Julia Lerman 在她的EF 书中有关于该主题的精彩章节。
Have you looked at the ObjectContext.MetadataWorkspace? It's not the easiest library to work with, but I was able to get all of the information that I needed.
Julia Lerman has a good chapter on the subject in her EF book.