Reputation: 8344
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.
Upvotes: 1
Views: 2226
Reputation: 1064254
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.
Upvotes: 1
Reputation: 45127
I think I understand what you want to do, but if not, let me know. You can make your abstract base class partial and pull the implementation you want up into that class. Alternatively, you could take your abstract class and encapsulate the functionality you want your child classes to have access to.
Upvotes: 0