Reputation: 740
If I want to compile my LINQ->SQL classes into a DLL to provide to my developers, how can I make it so that they can still hook into the various entity partial methods (OnValidate, for example)? I know that you cannot implement partial methods on a compiled assembly, but any suggestions on how I can extract this behavior (perhaps with events?) would be appreciated.
Upvotes: 0
Views: 173
Reputation: 35741
If I want to compile my LINQ->SQL classes into a DLL to provide to my developers
I dont think that this is a good idea. There are so many reasons why a LinqToSql Model might want to change. You will likely need to modify your model while discovering new insight into your domain etc.
By creating a seperate DLL "to provide to your developers" you create an artificial boundary that is likely to hinder efficiency in development. Getting a source control system might be more appropriate for what you may try to accomplish (beeing VERY vague here)
Upvotes: 0
Reputation: 6495
You may need to customize this solution for your needs, but a simple way of publishing events from partial methods can be done like so:
partial class LinqClass
{
public event Action<LinqClass, ChangeAction> OnValidating;
partial void OnValidate(ChangeAction action)
{
if (OnValidating != null)
{
OnValidating(this, action);
}
}
}
You may or may not need to pass along different parameters, but the Action
will support numerous.
Upvotes: 1
Reputation: 25277
As far as I am aware, you cannot.
When partial classes are encountered by the compiler, it combines them together to form a complete class. The only way I see your needs being fulfilled is to make your classes inheritable, but with L2S, this may prove to be more trouble than it's worth.
EDIT:
As for events, depending on the size of your L2S class count, it all depends on what you're willing to put in. This solution could work, but will take a long time to get right. Combining Interfaces
with events and custom handlers can get you there, just be prepared for the time investment if there are a large number of classes you want accessible.
Upvotes: 1
Reputation: 12975
I would handle this by publishing public events at any point you desire.
Upvotes: 0