views:

169

answers:

1

Hi,

One strange thing i've got to see in Entity Framework 4.0 V2 Auto Generated Classes(tt) is that the classes are not marked as Serializable. Although they are having DataContract attribute for WCF.

Now the problem is, when I store the POCO object into viewstate it throws me an exception saying that the class is not serializable.

If I generate the classes without the t4 templates or using the defualt class generating scheme, what i see is that the generated classes are having the Serializable attribute on them.

But unfortunately i can not make use of the default Entity Generation Scheme. Since I want to accomodate some custom logic to the autogenerated class which is possible through t4 templates only.

Now what i want to know is:

1) Why the Serializable Attribute is not there in the autogenerated class or am I making any mistake or i am towards a wrong approach.

2) Is it a good idea to customize the EF 4.0 T4 template to accomodate Serializable attribute.

Looking for your valuable suggestion.

Thanks,

Burhan Ghee

A: 

The purpose of T4 template is allow you to customize. Customize it fearlessly! You are not only encouraged to customize template, but also the edmx file that your template is based on. see this http://blogs.msdn.com/adonet/archive/2010/03/05/updated-data-model-designer-extension-starter-kit.aspx

Fred Yang