由于DynamicProxies,AppFabric因EF4(实体框架)代码优先模型而失败 [英] AppFabric fails with EF4 (Entity Framework) Code First Model because of DynamicProxies

查看:72
本文介绍了由于DynamicProxies,AppFabric因EF4(实体框架)代码优先模型而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用相关实体框架4代码优先数据模型的AppFabric的更新版本(截至2010年10月20日)。作为其中的一部分,我们将从SQL绘制项目到POCO对象并将这些对象存储在AppFabric中。 我们可以毫无问题地存储/检索项目


当我重新编译代码并尝试检索一个项目(我知道它仍然在缓存中)时,我得到了以下异常:


"反序列化程序无法加载要反序列化的类型,因为在程序集'EntityFrameworkDynamicProxies-ACME.Contracts中找不到类型'System.Data.Entity.DynamicProxies.ACMEVersionHisto_0274F07D5CB3ECB757E0533C2AD895AD967B6E8D00FAB202E813E9C48E9493A5',
Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'。检查被序列化的类型与被反序列化的类型具有相同的合同并使用相同的程序集。"


我相信EF4使用的动态代理类支持POCO模型使用不同的签名重新编译,这些签名与那些仍然存储在缓存中的项目不向后兼容 - 即使类的结构保持不变
(即相同的属性/字段/等)。 我猜是有道理的,但它使这些最新的两种MS技术完全不兼容,我很难相信。


值得注意的是,我们曾经使用HttpRuntime.Cache来满足我们的缓存要求,并且从来没有遇到任何问题。


任何帮助,非常感谢 - 谢谢。


 

解决方案

 


我通过使用db context配置对象上的ProxyCreationEnabled属性禁用代理创建找到了解决方案。  我正在使用EF 4.1。


但是这会禁用更改跟踪并删除对延迟加载的支持,这两者都不需要。


<标题="与POCO实体合作"href ="http://msdn.microsoft.com/en-us/library/dd456853.aspx"> http://msdn.microsoft.com/en-us/library/dd456853 .aspx


-Thanks。


Brian






I am using the releast version of AppFabric (as of 20 Oct 2010) against an Entity Framework 4 Code-First data model. As part of this, we are drawing items from SQL into POCO objects and storing those objects in AppFabric.  We can store/retrieve items with no problems.

When I recompile the code and try to retrieve an item (which I know is still in the cache), I get the following exception:

"The deserializer cannot load the type to deserialize because type 'System.Data.Entity.DynamicProxies.ACMEVersionHisto_0274F07D5CB3ECB757E0533C2AD895AD967B6E8D00FAB202E813E9C48E9493A5' could not be found in assembly 'EntityFrameworkDynamicProxies-ACME.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Check that the type being serialized has the same contract as the type being deserialized and the same assembly is used."

I believe that the dynamic proxy classes used by EF4 to support the POCO model are recompiled with different signatures which are not backwards compatible with those items still stored in the cache - even though the structure of the class remains unchanged (ie same properties/fields/etc).  Makes sense I guess, but it makes these latest two MS technologies completely incompatible, which I find hard to believe.

Of note, we used to use the HttpRuntime.Cache for our caching requirements, and never had any problems.

Any help, much appreciated - thanks.

 

解决方案

 

I found a solution to this by disabling proxy creation using the ProxyCreationEnabled property on the db context configuration object.  I am using EF 4.1.

This does however disable change tracking and removes support for lazy loading, neither of which I needed.

http://msdn.microsoft.com/en-us/library/dd456853.aspx

-Thanks.

Brian




这篇关于由于DynamicProxies,AppFabric因EF4(实体框架)代码优先模型而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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