This is a migrated thread and some comments may be shown as answers.

All Entities Inherit from a base class

3 Answers 311 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Erik
Top achievements
Rank 2
Erik asked on 08 Jun 2011, 11:46 AM
Hi,

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?

Thanks,

Erik

3 Answers, 1 is accepted

Sort by
0
Accepted
Ralph Waldenmaier
Telerik team
answered on 11 Jun 2011, 10:50 AM
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.

Greetings,
Ralph
the Telerik team
Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
0
Mercede
Top achievements
Rank 2
answered on 18 Jul 2015, 03:59 PM

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.

 

0
Boyan
Telerik team
answered on 22 Jul 2015, 03:33 PM
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();
    baseClass.Name="YourNamespace.BaseX";
    @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.

Regards,
Boyan
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Tags
General Discussions
Asked by
Erik
Top achievements
Rank 2
Answers by
Ralph Waldenmaier
Telerik team
Mercede
Top achievements
Rank 2
Boyan
Telerik team
Share this question
or