All Entities Inherit from a base class

Thread is closed for posting
4 posts, 1 answers
  1. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 08 Jun 2011 Link to this post


    I would like my entities to inherit from a base class. I see a "Base Class:" option in the "Mapping Details Editor > inheritance..." but that is always disabled. Also no option is available in the new domain wizard. When I google on it, I find myself in the old OpenAccess docs, again.

    Could you give me some pointers?


  2. Answer
    Ralph Waldenmaier
    Ralph Waldenmaier avatar
    202 posts

    Posted 11 Jun 2011 Link to this post

    Hello Erik,

    you can define the inheritance behavior in the Visual Designer, by adding a 'Inheritance' item to your model. Click on the 'Inheritance' item in your Toolbox and then first select the derived class and second the base class. This should be all. The process is described here. This documentation is related to the new Visual Designer features of OpenAccess.

    If you want to find the vertical approach, you can find it here.
    I hope this helps.

    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
  3. Mercede
    Mercede avatar
    9 posts
    Member since:
    Dec 2008

    Posted 18 Jul 2015 Link to this post

    I have a question that is similar but actually different. 

    We are working on migration of a component of a working system. We have entities in the model but to have other parts of the system interact with these entities, they ALL need to be derived from a certain base class (lets suppose) XBase. We currently have 56 entities in our model and we have not been able to find any way to have all entities inherit from XBase. Entity Framework gives the option by modifying the T4 template class to have all the entities derive from a single base class. Is there any such option or workaround in OpenAccess?

    XBase is found in another component and the components of the system would only be able to use the entities of OpenAccess model if they are derived from XBase only.


  4. Boyan
    Boyan avatar
    100 posts

    Posted 22 Jul 2015 Link to this post

    Hello Mercede,

    Could I kindly ask you which version of Telerik Data Access you would use and do you plan to use the Visual Designer?
    If so, the Visual Designer does allow code generation modification. You should first copy the code generation templates locally, as described in this documentation article (just the first step named: 1. Copy the Templates Locally). Once you have the templates copied, please locate the Engine.ttinclude and on line 86 please add the following code:
    if(@class.BaseClass == null)
        var baseClass = new Telerik.OpenAccess.CodeGeneration.CodeClass();
        @class.BaseClass = baseClass;  

    Then please re-save the .rlinq file, at that point all the classes should inherit from the YourNamespace.BaseX class.

    If you chose this approach you should have in mind that we recommend the YourNamespace.BaseX to be an abstract class as trying to persist instances of that class will result in an error. Another thing is that, if using xml mapping, you are not going to be able to map its properties to database columns.

    With this approach you will grantee that all your classes have a common base class. If you have some further requirements please described them along with your implementation scenario in more detail. This will allow us to advice you better in that particular situation.

    I hope this is helpful. Do not hesitate to contact us with any more questions.

    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Back to Top