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

Can let the generate context class more clearly?

3 Answers 54 Views
Design Time (Visual Designer & Tools)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jin
Top achievements
Rank 1
Jin asked on 31 Aug 2012, 06:06 AM
After I generate the context class with Wizad, I feel following two points which is not convenient:
1.When I want to see the source code of the generated class, I need to expand the tt file first and double-click cs file. Whether consider to display cs file first while double clicking tt file or put the cs as the first level because I think nobody want to see the content in tt file?

2.I checked all generated code in context class, it's not very clearly.For example, the GetBackendConfiguration method is no need to included because I think no developer will not modify it in most scenario. I think you need to consider to maintain the code in one place instead of every generated context class, at the same time, every context class to have a chance to override the code in one place.

3 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 04 Sep 2012, 03:44 PM
Hi Jin,

The .tt file that the wizard creates is a text template which is required in order to generate the context class. The TextTemplating engine of Visual Studio works this way, so that all generated files are nested one level deeper in the Solution Explorer than the tt file that has created them. Unfortunately we do not have much control over this behavior. What you can do however is keep the generated .cs file in your project and delete the .tt one. If you need to regenerate the context class later, you could run the wizard again and do the same procedure.

You are right that you could generate multiple context classes for the same model and they would contain similar code. However, normally you do not need more than one class. If you want to keep the context in a separate project, you could generate one with the aforementioned wizard and disable the context generated by default from the rlinq file using the Model Settings dialog. Just uncheck the Generate Context option and save the diagram.

Kind regards,
Alexander
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
0
Jin
Top achievements
Rank 1
answered on 05 Sep 2012, 01:32 AM
Hi Alexander,

Thanks for your response.
For your first answer,  whether there is a way to only generate cs class instead of delete tt file manually after created?
For your second answer, I mean the generated context class is not clearly and can be optimized it as below:
For example, I will generate a context class which is related Function entity:

public partial class MaintainRuleDA : OpenAccessContext, IMaintainRuleDAUnitOfWork
{
public MaintainRuleDA()
:base(@"BTSIS", "System.Data.SqlClient", "BTSIS.BusinessEntity.MaintainRuleEN.rlinq")
{ }

public IQueryable<Function> Functions 
{
    get
    {
        return this.GetAll<Function>();
    }
}


public interface IMaintainRuleDAUnitOfWork : IUnitOfWork
{
IQueryable<Function> Functions 

get;
}
}

In most situation, developer will only use default constructor. If developer want to more control, they can add some constructor by himself and no need to display all constructor. No need to display how to get configuratoin and metadataSource in generated class. 
0
Alexander
Telerik team
answered on 06 Sep 2012, 02:57 PM
Hello Jin,

Unfortunately there is no way to generate the context without the tt file. This is how the T4 code generation engine works.

Regarding the code itself, please note that you can customize what is generated by modifying the code generation templates that OpenAccess uses. Those templates are installed at C:\Program Files\Telerik\OpenAccess ORM\dsl2010\CodeGenerationTemplates\CSharp\Includes. If you are working with Visual Studio 2008 or 2012, replace dsl2010 with dsl2008 or dsl2012 accordingly in this path.

For example, if you want to remove the unneeded constructors of the context class, open the Context.ttinclude file in a text editor and go to line 217. There you will see how the constructors are generated.
    // Generate COnstructors BEGIN
#>
 
    public <#= contextClass.Name #>()
        :base(connectionStringName, backend, metadataSource)
    { }
     
    public <#= contextClass.Name #>(string connection)
        :base(connection, backend, metadataSource)
    { }
 
    public <#= contextClass.Name #>(BackendConfiguration backendConfiguration)
        :base(connectionStringName, backendConfiguration, metadataSource)
    { }
         
    public <#= contextClass.Name #>(string connection, MetadataSource metadataSource)
        :base(connection, backend, metadataSource)
    { }
     
    public <#= contextClass.Name #>(string connection, BackendConfiguration backendConfiguration, MetadataSource metadataSource)
        :base(connection, backendConfiguration, metadataSource)
    { }
         
<#+
    // Generate COnstructors END

Just delete the ones that you do not want to use, save the template file and then open and save the .rlinq file in order to regenerate the source code.
Hope that helps.

All the best,
Alexander
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Tags
Design Time (Visual Designer & Tools)
Asked by
Jin
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Jin
Top achievements
Rank 1
Share this question
or