1

I am using Linq-To-SQL and I would like to attach an interface to each of my entities.

I can edit the designer.cs file and accomplish this.

However, when I make a changes to the dbml through the UI it rewrites the whole designer.cs and I lose my changes.

Am I just going to have to deal with it, or is there a way to get around it?

I am doing this in the designer.cs file(the IMatchable is a custom interface of mine):

public partial class Error : INotifyPropertyChanging, INotifyPropertyChanged, IMatchable
{
   ...
}

1 Answer 1

5

Don't edit the designer file; the beauty of partial classes is that you can create a separate file with just

public partial class Error : IMatchable
{ }

(assuming that we are using implicit interface implementaion by virtue of having properties that match the required interface)

Small word of caution though: if you are using VS2008 and you have MyClasses.dbml and MyClasses.designer.cs, do not call this file MyClasses.cs - there is a bug in VS2008 that makes this a nuisance (you have to keep moving the using directives inside the namespace, or the code-generator breaks) - fixed in VS2010 though.

Also, if it was a single interface, that every type in your model implemented, you can cheat by specifying that at the object base-type in the DBML. The designer doesn't show this option, but if you edit the DBML manually it works fine.

Sign up to request clarification or add additional context in comments.

4 Comments

I tried that, but I left off the Interfaces it puts on there =(. I'll give it a go. Thanks.
@Blankasaurus - if those interfaces were already in the other half of the partial class, you don't need to re-add them. If it didn't pick them up, try checking you are in the right namespace, etc.
Perfect. Exactly what I was looking for. When I tried it before it was actually me failing at namespacing and not the lack of those interfaces.
Thank you for this, losing my own interfaces every time I touched the LINQ2SQL designer was driving me crazy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.