WCF + Entity Framework CodeFirst = DynamicProxies exception?

落爺英雄遲暮 提交于 2019-12-11 05:05:26

问题


I'm trying out EF CodeFirst CTP 5, and using it with WCF Data Services. I'm getting an error that Internal Server Error. The type 'System.Data.Entity.DynamicProxies.Person_C321D7A37002A1B42C3CBAECC27983D77F6B7FCC3F837175B2CBB55CCA66AF55' is not a complex type or an entity type.

If I use an edmx-generated Person off the db created by CF, I have no issue. In reading up, it seems that the lazy loading is screwing things up, and previous EF versions have let me turn off proxy generation with an option flag that's not present in the DbContext. There is a way to set up LazyLoading to false, but that doesn't apparently turn off proxy generation.

Thanks.


回答1:


Here's what you can do in EF code first CTP5:

((IObjectContextAdapter)context).ObjectContext.ContextOptions.ProxyCreationEnabled = false;

Alternatively, this is a bug in WCF data services in VS 2010 RTM. You can used the CTP1 of WCF Data Services that has this issue fixed.

Hope this helps.
Thanks
Pratik




回答2:


In CTP1, the binaries have been renamed to Microsoft.Data.Services.*.dll. Did you change the references to the new assemblies? I am pretty sure that this issue was fixed in CTP1. So just wanted to make sure it worked for you.

Thanks Pratik




回答3:


If you are using the new DbContext class, then you can make use of

Configuration.ProxyCreation = false

To disable the dynamic proxy creation



来源:https://stackoverflow.com/questions/5096680/wcf-entity-framework-codefirst-dynamicproxies-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!