I would like to extend a class generated by Linq To Sql to initialize when a new object (=row) is created.
I want to add rows to a child table when a parent row is created.
I was hoping to use the Oncreated (partial) method do something like this:
partial class Product {
partial void OnCreated() {
// Fill default rows for FK relations
this.Columns.Add(new ProductColumn {
Name = "Name", ColumnType = 1
});
this.Columns.Add(new ProductColumn {
Name = "Producer", ColumnType = 2
});
}
}
The OnCreated is called every time from the constructor. So also if the object will be loaded from the database after the call to OnCreated. And if the object is loaded from the database, do not want to execute the code.
So where can I add logic to my model to initialize an object(-graph)?