views:

31

answers:

1

Hi, all my entities have a common property which specifies the company they belong to, I would like to set this property in a method in my datacontext but I do not want to use the partial methods for each of the entity types that the datacontext provides, is there a method that receives any entity that is inserted throught the datacontext so that I can hook to it or override it and set the property using reflection? thanks.

+1  A: 

You could override the SubmitChanges method in your DataContext class and then perform necessary changes to your inserted/updated/deleted entities:

public partial class YourDataContext
{
    public override void SubmitChanges(ConflictMode failureMode)
    {
        ChangeSet changes = GetChangeSet();

        foreach (var entity in changes.Inserts())
        {
        }

        // you could do the same with updates and deletes

        base.SubmitChanges(failureMode);
    }
}
Alex
Thanks, that did it.
ryudice