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

6 posts, 0 answers
  1. Brian Mains
    Brian Mains avatar
    485 posts
    Member since:
    Oct 2008

    Posted 09 Apr 2012 Link to this post

    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.
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 10 Apr 2012 Link to this post

    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 >>
  3. DevCraft banner
  4. Brian Mains
    Brian Mains avatar
    485 posts
    Member since:
    Oct 2008

    Posted 10 Apr 2012 Link to this post

    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.
  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 11 Apr 2012 Link to this post

    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 >>
  6. Ian
    Ian avatar
    26 posts
    Member since:
    Jun 2012

    Posted 17 Apr 2012 Link to this post

    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 :)
  7. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 17 Apr 2012 Link to this post

    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 >>
Back to Top
DevCraft banner