views:

25

answers:

1

I implemented a generic way to get the object by id from Entities defined in Entity Framework.

But the problem is the object I got has a very weird type like this {System.Data.Entity.DynamicProxies.MyEntity_C71732021C3A9D6A58BDB6087D29E98CFDE09DA9D53AF0892AFB7918AEF7E61F}

And WCF will fail when serialize this object as the type of MyEntity.

How to make the generic type to be the specific type I want? Thanks.

+1  A: 

It sounds like you're using Entity Framework 4.0 POCO objects. If that's the case, MSDN has a great walk-through on how to get things working:

Walkthrough: Serialize POCO Proxies with WCF

Also take a look at:

Working with POCO Entities (pay close attention to the Serializing POCO Proxies section)

Justin Niessner
I think the problem is how to convert the type from MyEntity_C71732021C3A9D6A58BDB6087D29E98CFDE09DA9D53AF0892AFB7918AEF7E61F to MyEntity.
sza
@sza - That's what the article covers! It creates a new attribute that handles the resolution for you.
Justin Niessner
thank you. hmm, but i still got the error and type is not converted
sza
Pay close attention to step 13 in **To create and configure the WCF project**. Make sure you disabled lazy loading.
Justin Niessner
Thanks! It works. I added the decorator ApplyDataContractResolver and disabled the lazy loading.
sza