Paul
Paul

Reputation: 36319

WCF + Entity Framework CodeFirst = DynamicProxies exception?

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.

Upvotes: 1

Views: 1621

Answers (3)

AlanFoster
AlanFoster

Reputation: 8306

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

Configuration.ProxyCreation = false

To disable the dynamic proxy creation

Upvotes: 0

Pratik
Pratik

Reputation: 607

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

Upvotes: 0

Pratik
Pratik

Reputation: 121

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

Upvotes: 4

Related Questions