1

In LINQ to SQL, Can we inherit our entity classes from some other class or interface. I have some common work for all my entities, which I want to code at some common place and call it once.

Regards Parminder

2 Answers 2

3

@Jason's answer is useful for manually tweaking each class. To modify all generated classes to use the same base class there is an attribute in the .dbml file that can be edited manually (no UI for it in VS2008).

Add a EntityBase xml attribute into the <Database> xml element, its value is the full name of the base class.

<Database ... EntityBase="MyNamespace.MyBaseClass" ...>
...
</Database>

Its used by the LINQ to Entity Base project.

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

Comments

2

Yes, this is possible. Use partial classes. If MyEntity is your LINQ to SQL entity class, add a partial implementation as follows:

partial class MyEntity : MyBaseClass, IMyInterface {
    // do it
}

You can even make your entity class an abstract class.

Comments

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.