开发者

Entity Framework 4 + POCO with custom classes and WCF contracts (serialization problem)

Yesterday I worked on a project where I upgraded to Entity Framework 4 with the Repository pattern. In one post, I have read that it is necessary to turn off the custom tool generator classes and then write classes (same like entites) by hand. That I can do it, I used the POCO Entity Generator and then deleted the new generated files .tt and all subordinate .cs classes. Then I wrote the "entity classes" by myself.

I added the repository pattern and implemented it in the business layer and then implemented a WCF layer, which should call the methods from the business layer. By calling an Insert (Add) method from the presentation layer and everything is OK. But if I call any method开发者_StackOverflow that should return some class, then I get an error like (the connection was interrupted by the server).

I suppose there is a problem with the serialization or am I wrong? How can by this problem solved?

I'm using Visual Studio S2010, Entity Framework 4, C#.

UPDATE:

I have uploaded the project and hope somebody can help me! link text

UPDATE 2:

My questions:

  1. Why is POCO good (pros/cons)?
  2. When should POCO be used?
  3. Is POCO + the repository pattern a good choice?
  4. Should POCO classes by written by myself or could I use auto generated POCO classes?


Why is POCO good (pros/cons)?

  • Work with EF4, NH and few others -ORM

When should POCO be used?

  • Depends on usage

Is POCO + the repository pattern a good choice?

  • For WCF

    POCO- You have track changes manually,

    STE Automatic Change Tracking is done.

Should POCO classes by written by myself or could I use auto generated POCO classes?

  • T4 would be better choice.


Regarding your WCF serialization issues, in the t4 template, we needed to set the ProxyCreationEnabled = false; on the ContextOptions

http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontextoptions.proxycreationenabled.aspx


For POCO serialization you'll need the ProxyDataContractResolver.

You may wnat to check out this MSDN Walkthrough article on building a custom attribute that you can apply to your service contract to serialize the POCO proxy types.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜