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

Custom Unit of Work Interface - Why No Stored Procedure Listings?

5 Answers 144 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.
Brian Mains
Top achievements
Rank 1
Brian Mains asked on 09 Apr 2012, 06:29 PM
Hello,

For open access, the generator generates an IMyContextUnitOfWork interface... that leaves out stored procedure definitions.  Why is that?  Why not include stored procs into this interface too?

Thanks.

5 Answers, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 10 Apr 2012, 04:18 PM

Hello Brian,

I have slightly modified the context code generation template to enable the generation of the stored procedure method definitions within the IUnitOfWork interface.

Please find the modified template attached to my answer. You need to place the template under the following directory [OpenAccess_Install_Dir]\dsl2010\CodeGenerationTemplates\CSharp\Includes.

Hope that helps.


All the best,
Damyan Bogoev
the Telerik team
Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
0
Brian Mains
Top achievements
Rank 1
answered on 10 Apr 2012, 10:45 PM
Hey,

Thanks, I'm using VB.  If you could just identify the areas that have changed over the original, I can translate it too.  In any case, I'd also like to know that for educational purposes, if you don't mind.

Thanks.
0
Damyan Bogoev
Telerik team
answered on 11 Apr 2012, 09:53 AM
Hello Brian,

Firstly I want to apologize for the inconvenience caused.
I have done the following changes in the Context.ttinclude template in order to generate the stored procedure methods in the IUnitOfWork interface:
-    Modified the GenerateContextInterface method to accept one additional parameter  and added an additional method call to the GenerateContextInterfaceMethods method in the GenerateContextInterface;

private void GenerateContextInterface(Telerik.OpenAccess.CodeGeneration.CodeInterface codeInterface, Telerik.OpenAccess.CodeGeneration.CodeClass context)
{
    this.PushIndent("\t");
    this.GenerateComments(codeInterface.Comments); 
    string interfaceSignature = GetInterfaceSignature(codeInterface);
    this.WriteLine(interfaceSignature);
    this.WriteLine(classOpenToken);
    this.GenerateContextInterfaceMembers(codeInterface);
    this.GenerateContextInterfaceMethods(context);
    this.WriteLine(classCloseToken);
    PopIndent();
}

-    Defined a new method which generates the needed method definitions in the interface:

private void GenerateContextInterfaceMethods(Telerik.OpenAccess.CodeGeneration.CodeClass context)
{
    System.Collections.Generic.IEnumerable<Telerik.OpenAccess.CodeGeneration.CodeFunction> functions = context.Functions;
    PushIndent("\t");
    functions.ForEach(
        function =>
        {
            bool generateRef= false;
            if(function.FunctionType == Telerik.Data.Dsl.DomainFunctionType.Void)
            {
                generateRef = true;
            }
            string clrParametersDeclaration = GetClrParametersDeclarationForFunction(function, generateRef);   
 
            string returnType = function.ReturnType;
            if (string.IsNullOrEmpty(returnType))
            {
                 returnType = "object";
            }
            string methodToBeExecuted= string.Concat("this.ExecuteQuery<",returnType,">");
            string resultType= string.Concat("IEnumerable<", returnType, ">");
            if(function.FunctionType == Telerik.Data.Dsl.DomainFunctionType.Void)
            {
                methodToBeExecuted = "this.ExecuteNonQuery";
                resultType = "int";
            }
            else if(function.FunctionType == Telerik.Data.Dsl.DomainFunctionType.PrimitiveType)
            {
                methodToBeExecuted = string.Concat("this.ExecuteScalar<", returnType,">");
                resultType = function.ReturnType;
            }
 
            this.WriteLine(string.Empty);
#>
<#=resultType#> <#= function.Name #>(<#= clrParametersDeclaration #>);
<#+
        });
 
    this.PopIndent();
}

-    Modified the GenerateContextFileBlock to call the GenerateContextInterface method by passing the context variable:

this.GenerateContextInterface(contextInterface, context);

Hope that helps. If any other question arises, do not hesitate to contact us back.

Kind regards,
Damyan Bogoev
the Telerik team
Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
0
Ian
Top achievements
Rank 1
answered on 17 Apr 2012, 05:30 AM
Will this be a part of a future release of OpenAccess?

On a related note, I've found lots of places where T4 templates are given in knowledge-base articles, discussion forum posts, etc.  Is there a single place we can visit to get the latest T4 templates that we can use with OpenAccess?  It's ok if the answer is "no", but if it is "no", would you consider starting one (even if it's just a sticky in the forum)?

Thanks :)
0
Damyan Bogoev
Telerik team
answered on 17 Apr 2012, 03:10 PM

Hi Ian,

Yes, we will improve our T4 templates for the next release of the product.

Any changes made to the product’s code generation templates will be released with the product. Actually you could find all of the customized templates T4 templates in our Code Library.

Greetings,
Damyan Bogoev
the Telerik team
Share your passion about the Telerik Open Access by voting for Telerik's powerful ORM tool here >>
Tags
General Discussions
Asked by
Brian Mains
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Brian Mains
Top achievements
Rank 1
Ian
Top achievements
Rank 1
Share this question
or