We're using sqlmetal to generate our DBML, run it through a transformation, then use sql metal to generate the DataContext classes -- additionally, I want to automatically generate some validation for the entities based on some metadata that we store in the database about each entity and it's attributes. For example, if an entity has what I know to be an "EmailAddress" field of meta type "Email", I'd like to create the OnValidate method for the Email entity to check that it adheres to my regular expression. That's all fine and dandy, and I can do it like this in another file:
public partial class MYENTITY
{
partial void OnValidate(System.Data.Linq.ChangeAction action)
{
if(action != System.Data.Linq.ChangeAction.Delete)
{
//check the validity of my email field or anything else
}
}
}
How can I do this while still allowing the developers who want to use this DataContext the ability to hook their own logic into the OnValidate method for this entity? In our situation, this would be business logic specific to the application being developed. The additions I describe above are just safeguards to ensure that data that is getting to the database is as I expect it to be.
Thanks for any help. New here, so apologies if I did something wrong.