The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

DesertRambler (4) [Avatar] Offline
#1
I am trying to follow along in Chapter 23, but I am using Visual Studio 2012. By default, this means that my Entity Framework model, created from the AdventureWorks database (2008 version) is using Entity Framework 5 with the DbContext instead of ObjectContext. I am having problems with the Silverlight-enabled WCF Service I created and it appears to be related to not being able to pass (or serialize) the Employee class created by the EF Model. If I change the datatype to an IList<> of any other type, value or locally-created class object, it works fine. But passing the Employee EF class fails.

Has anyone else experienced this, and does anyone know what the solution is?

Thank you,
Cindy
DesertRambler (4) [Avatar] Offline
#2
Re: Chapter 23 using Visual Studio 2012?
The solution is to turn off Proxy Creation on the DbContext. It can either be done each time you create an instance of the context:

var context = new AdventureWorksEntities();
context.Configuration.ProxyCreationEnabled = false;

Or you can modify the DbContext.TT file to add the line for code-generating the DbContext class with it:

public <#=code.Escape(container)#>()
: base("name=<#=container.Name#>"smilie
{
<#
if (!loader.IsLazyLoadingEnabled(container))
{
#>
this.Configuration.LazyLoadingEnabled = false;
<#
}
#>
this.Configuration.ProxyCreationEnabled = false;
}


I hope this helps somebody. I have wasted almost a whole day fighting this!
DesertRambler (4) [Avatar] Offline
#3
Re: Chapter 23 using Visual Studio 2012?
Except now I cannot retrieve the Contact object through the navigation property (in the 2008 database, it's actually called Person.) With Proxy Creation turned off, it won't retrieve the child object.

I tried putting a .Include("Person") on the end of my entity retrieval method and it works fine in the service function (I am using a temporary variable), but WCF won't pass it back. Not sure what else I have to do to get that to work.

I think this is all an academic exercise because in reality I will be using RIA Services, but just wondering how to get this to work anyway.