Search code examples
wcf-data-servicesef-code-first

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.


Solution

  • 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