Starting from an EF 4 entity diagram and using T4 templates one can create POCO classes that can be used inside the Domain Model. The generated code looks like this:
public partial class Product
{
public virtual int Id
{
get;
set;
}
public virtual string Name
{
get;
set;
}
//and so on
}
Is there any elegant approach to add my own code for implementing the properties? for example, the Name setter I would like to be implemented by lowering all the characters. I would like that my code resist to repeated regeneration of the POCO classes from the EF diagram.
This requirement is somewhat similar to adding validation code to the POCO classes. This issue is already solved by creating a separate validation class and linking it to the POCO through the MetadataType
attribute. That separate validation class is not overwritten by repeatedly regenerating POCOs from the EF diagram.
Thanks,
Lucian
No there is no easy way to do that. You must not touch generated code because your changes will be deleted after each regeneration. You options are: