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

EntitiesModel Access Modifier

1 Answer 49 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dan
Top achievements
Rank 1
Dan asked on 25 Mar 2015, 09:22 PM
Is there any way to change the access modifier of the generated EntitiesModel?  I'm trying to create a n-Tier architecture which means that the only thing I want exposed out of my Repository layer is the interfaced classes that I create.  I want the EntitiesModel and all subsequent generated code to remain internal to the assembly.  I have set all the generated domain classes to Assembly and they are tagged with the "internal" access modifier, but the code is still exposing EntitiesModel and IEntitiesModelUnitOfWork.  Any way to also sent those to assembly/internal?

Thanks

1 Answer, 1 is accepted

Sort by
0
Doroteya
Telerik team
answered on 30 Mar 2015, 02:01 PM
Hi Dan,

Thank you for your interest in Telerik Data Access.

In general, it is possible to achieve the needed restriction by a modification of the code generation templates, but the complete scenario will not work. Currently, the runtime of Data Access does not support interface abstraction.

If you are interested in the code generation modification steps anyway, here they are:
1. Copy the Data Access code generation templates in your project as described in the Copy the Templates Locally section of this documentation article. Note that the article is for another scenario. It is important to execute only the steps in the Copy the Templates Locally section.
2. Open the ContextGenerator.ttinclude template and replace the code on line 53 with the following:
internal partial class <#= contextClass.Name #> : <#= contextClass.BaseClass.Name #>, <#= contextClass.IUnitOfWorkInterface.Name #>
3. Open the InterfacesGenerator.ttinclude template and replace the entire GenerateInterfaceSignature() method with the following:
    protected void GenerateInterfaceSignature(Telerik.OpenAccess.CodeGeneration.CodeInterface codeInterface)
    {
        string implementsStr = string.Empty;
        if(codeInterface.Implements.Any())
        {
            implementsStr = " : " + string.Join(", ", codeInterface.Implements.Select(i => i.Name).ToArray());
        }
        if(codeInterface.Name.Contains("UnitOfWork"))
        {
#>
internal interface <#= codeInterface.Name #><#= implementsStr #>
<#+
        }
        else
        {
#>
<#= codeInterface.TypeAccessModifier.ToCode() #> interface <#= codeInterface.Name #><#= implementsStr #>
<#+ 
        }
    }
4. Save the two templates.
5. Open the .rlinq file in Visual Designer, move a class on the diagram and save the .rlinq file.

At this point, the context class and the interface should be internal.

I am sorry for the inconvenience caused. Do let us know, if you need further information.


Regards,
Doroteya
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Data Access Free Edition
Asked by
Dan
Top achievements
Rank 1
Answers by
Doroteya
Telerik team
Share this question
or