I'm creating an abstract class that can be inherited in a partial class of a LINQ to SQL class. The LINQ to SQL class contains a bunch of built-in partial methods. Is there a way that I can implement one or more of the partial methods in the abstract class? I know that partial methods can only be contained within partial classes or structs. I'm sure there's got to be another way to do it.
Here's more detail:
Hope that helps explain more.
Partial methods are not usable over inheritance. You could add regular methods to the abstract base class, but they won't automatically "pair" with the partial method declarations. So: no. You can, of course, simply have the partial method implementation call into the base-class.
Note also that if the common code relates to things like audit (who/when), you can also do this by overriding the DataContext
's SubmitChanges
method, and calling GetChangeSet
:
public override void SubmitChanges(ConflictMode failureMode)
{
ChangeSet delta = GetChangeSet();
//... use delta.Updates, delta.Inserts and delta.Deletes
base.SubmitChanges(failureMode);
}
Finally, note that you can also specify a common base-class for all your entities in the dbml (like so); you don't have to do it by hand in each partial class.