If you want to create a custom insert or update for ASP.NET Dynamic data and LinqToSQL then you will have to perform the following steps:
1) Create a partial class for the entity you want to make the insert/update custom. For example if you had a table name employees then your code would look like this:
2) Create a Metadata for that class - EmployeesMetadata. Now your code should look like this:
Note: I prefer to put the metadata inside the object which is using it, but you can put it outside. I chose to put it inside because otherwise it will be visible through all the namespace however it is intended to be used only in one place.
3) Now that we have the class above we are able to create our custom Insert and Update methods. Add these methods to the our existing Employees partial class.
Insert Method Code:
Update Method Code:
4) Now that you have these two methods that doesn't mean that LinqToSQL will use them instead of the original insert and update action. We need to tell it to use our methods instead. To do that we will need to modify the DataContext. My DataContext's name is "MyDataContext". we need to indicate that instead of insert do our custom insert and instead of update do our custom update.
This was the final changes, now you have the custom insert and update working.
Any questions let me know.