How to create domain method for stored procedure?

4 posts, 0 answers
  1. Jin
    Jin avatar
    80 posts
    Member since:
    Jun 2012

    Posted 23 Aug 2012 Link to this post

    As your guide http://www.telerik.com/help/openaccess-orm/developer-guide-crud-sp-support-getting-started-sp-editor.html, I can get a generated domain method for a specified stored procedure in one project. But if I have two projects, the one is put Domain Entity calss and another one put Domain Context class, how to get the generated domain method?
  2. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 24 Aug 2012 Link to this post

    Hi Jin,

    In general, OpenAccess generates the domain methods for the stored procedures in the context file of the domain model. So, if you want to call a domain method you need to reference the context assembly from your project and create an instance of the context in it. Moreover, if the called method returns a non-scalar value but a persistent type or complex type you will have to add a reference in your project to the entities assembly as well.

    In fact, if you provide us with a more detailed description of your scenario, we might be able to give you a better advise. 

    If additional questions come up, do not hesitate to get back to us.

    Kind regards,
    Doroteya
    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!
  3. DevCraft banner
  4. Jin
    Jin avatar
    80 posts
    Member since:
    Jun 2012

    Posted 24 Aug 2012 Link to this post

    In fact, I have two projects. The one is used to create entity class with Domain Module wizard without to check generate Context class option. Another project is used to create context class with Domain Context wizard. Now if I select one store procedure in Domain Module wizard and want to create a corresponding method, it will not auto generate the method in context class which is in another context project because the first project only have entity class and not include context class.
  5. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 29 Aug 2012 Link to this post

    Hello Jin,

    Indeed, the context generated with the Domain Context wizard does not include the domain methods created in the domain model. This is an additional feature in our backlog and it will be implemented for one of our future releases.

    In the meantime, we offer the following workaround:

    Creating the Domain Entities assembly
        1. Generate a domain model with the Generate Context option selected (named EntitiesModel for example)
        2. Open the .rlinq file in Visual Designer
        3. Find the stored procedure in the Model Schema Explorer
        4. Right-click on it and select Create Domain Method
        5. In the Stored Procedure Editor specify a name for the method, a result type and click OK
        6. Save the .rlinq file, so that the context is regenerated

    Creating the Domain Context assembly
        1. Add a Class Library to your project
        2. Delete the Program.cs file from it
        3. Add references to the Domain Entities assembly, Telerik.OpenAccess.dll and Telerik.OpenAccess.35.Extensions.dll
        4. Add a Telerik OpenAccess Domain Context item to the assembly
        5. Give it a name (OpenAccessDomainContext, for example), choose a metadata source, select the entities and click Finish

    Copying the domain methods
        
    1. Expand the EntitiesModel.rlinq tree in the Domain Entities assembly
        2. Open the context file (EntitiesModel.cs)
        3. Select the domain methods you want to use
        4. Paste them in the OpenAccessDomainContext.cs file before the GetBackendConfiguration() method

    Clearing the context in the Domain Entities assembly

       1.  Open the .rlinq file in Visual Designer
        2. Right-click on it and select Show Model Settings…
        3.
    Choose the Code Generation tab
        4. Deselect the Generate Context option
        5. Click OK
        6.
    Save the .rlinq file so that it clears the content of context and not add code there anymore

    Creating the UI
        1. Add a console application to your solution
        2. Copy the App.Config file from the Domain Entities assembly to it
        3. Add references to the Domain Entities assembly, to the Domain Context assembly, to Telerik.OpenAccess.dll and Telerik.OpenAccess.35.Extensions.dll
        4.
    In the .cs file write some code to use the method
        5. Enjoy the output

    Let us know if that works for you.

    All the best,

    Doroteya
    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!
Back to Top