views:

128

answers:

1

Can I serialize POCO classes? I'm using the C# POCO entity generator.

I tried to edit the .tt file which generates the entity classes to add the Serializable attribute. Is it right?

+1  A: 

You're using POCO proxies, not pure POCOs. Pure POCOs can be serialized if (obviously) they're serializable. Proxies might not be.

Craig Stuntz
How can I serialize POCOs if I'm using the ADO.NET POCO Entity Generator for generating the POCO entities? And when I set the context's ProxyCreationEnabled property to false, proxy creation is already disabled so I'm sure I'm not using those proxies.
jean27
You can always serialize real POCOs. If you're using proxies, which aren't really POCOs, then you should project onto real POCOs. I generally project onto anonymous types before serializing, as this guarantees no circular references, which typically kill serialization anyway.
Craig Stuntz