Entity Framework 4.0 Autogenerated Classes Not Marked as Serializable

One strange thing I should see in Entity Framework 4.0 V2 Auto Generated Classes (tt) is that classes are not marked as Serializable. Although they have a DataContract attribute for WCF.

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

If I generate classes without t4 templates or using the defualt class generation scheme, then I see that the generated classes have the Serializable attribute on them.

But, unfortunately, I cannot use the default entity generation scheme. Since I want to post some custom logic for an auto-generated class, which is only possible with t4 templates.

Now I want to know:

1) Why the Serializable attribute does not exist in the auto-generated class, or am I making any mistake, or am I mistaken.

2) Is it good to configure the EF 4.0 T4 template to accommodate the Serializable attribute.

Look for your valuable suggestion.

Thank,

Burhan ghee

+3
source share
2 answers

Yes, you can change the template. See adding the [DataMember] [DataContract] attributes in the POCO Framework Entity Framework for exactly what you need to do to fix your template. Look specifically at the WriteHeader function in the template.

+3
source

Source: https://habr.com/ru/post/1743776/


All Articles