实体框架 - 中等信任
我正在尝试让实体框架在中等信任度下工作。我尝试过拆分文件并使用单独的程序集,但我似乎遇到了一个又一个问题。
我将 EDMX 移至单独的程序集,这会导致将单个 .dll 输出到站点 /Bin 目录。我在 web.config 中引用了如下内容。
<add name="ApplicationDB" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Application.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
<add name="ShopEntities" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Application.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
每当我尝试访问其中一个实体类时,都会收到 ArgumentException:“已添加具有相同键的项目。”这对于中等信任度至关重要,但我似乎已经没有选择了。任何建议都非常感激。
I'm trying to get the entity framework working in medium trust. I've tried splitting the files and using a separate assembly but I seem to have one problem after another.
I moved the EDMX to a separate assembly, which causes a single .dll to be outpit to the sites /Bin directory. I'm referencing this as below from web.config.
<add name="ApplicationDB" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Application.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
<add name="ShopEntities" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Application.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
Whenever I try to access one of the entity classes, I get an ArgumentException: 'An item with the same key has already been added.' It's critical this works with medium trust, but I seem to be running out of options. Any advice greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在中等信任度下使用 Entity Framework 3.5。但是,在 Windows 7 和 Windows Server 2008 上运行此程序存在问题。微软为此发布了补丁。请阅读此处了解更多信息信息。
You can use Entity Framework 3.5 in medium trust. However, there is a problem with running this on Windows 7 and Windows Server 2008. Microsoft released a patch for this. Read here for more info.
将 EDMX 和所有分部类移至单独的程序集是最终的解决方案。
Moving the EDMX and all partial classes to a separate assembly was the eventual solution.