You are right those two options are the usual solutions for such problems.
It is true that option 1 requires a lot of code and in some cases will complicate the other code as at the end in your code you should work with the wrapped class but should add the underlying persistent class to the data context in order to store it.
I can suggest you the following approaches in addition:
1. You can keep the classes as they are implemented at the moment if you map the using our code only fluent API
. This would work well if you don't need the designer.
2. You can leverage the OnPropertyChanging and OnPropertyChanged events
to place your logic instead of adding it in the setters.
3. You can define partial methods to be executed before and after the actual value is set in the setter. The code would look like this:
._full_name = value;
Here you can see I have defined 2 partial methods and they are called in the property setter. To utilize them you should define the body of the method in a partial file for the same class. If the method body is not defined the compiler will remove the method call. With a simple customization in our out-of-the-box code generation templates you can get those methods generated for each property in all classes automatically. For your convenience I have prepared the code generation modifications (see the attached file). This
article describes how to proceed with custom code generation, once you copy the templates locally as described in the article you need to replace the attached file and you are done.
I hope this helps.
OpenAccess ORM is now Telerik Data Access
. For more information on the new names, please, check out the Telerik Product Map