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

Using Stored procedures in Entity Model with a service

3 Answers 107 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andrew
Top achievements
Rank 1
Andrew asked on 09 Aug 2012, 09:07 PM
I created an entity model of my database tables. I want to use the stored procedures i have generated and I was able to follow the help guides to create a domain method which I see gets generated correctly. My question is I went ahead and created a OpenAccess WCF Service. Now I cant figure out how I would be able to use that custom stored procedure from my client side application in code.

3 Answers, 1 is accepted

Sort by
0
Viktor Zhivkov
Telerik team
answered on 14 Aug 2012, 11:21 AM
Hello Andrew,

After mapping your Stored Procedures to Domain Methods in OpenAccess Designer you have to expose these methods through the WCF Service manually.
For procedures that return primitive types (like string, integer, boolean and etc.) and entity types the procedure is straight forward:
  1. Add partial extension for the IEntitiesModel interface (the interface of the service contract).
  2. Create there a public method marked as [OperationContract] for each Stored Procedure you would like to expose to the service. Fill in the correct return type and the correct parameters.
  3. Add partial extension for EntitiesModel.svc.cs class (the implementation of your service contract). Implement all of the newly added methods from the service contract interface. You can use the Domain Methods mapped earlier (in my example GetLastErrorId is a stored procedure that accepts single int parameter and returns a single int value): 
    public int GetLastErrorId(int securityFlag)
    {
        return this.unitOfWork.GetLastErrorId(securityFlag);
    }
  4. Change IEntitiesModel.cs interface definition to include "partial" keyword. This step should be repeated after each execution of Add OpenAccess Service wizard, because the file gets regenerated each time. We will add the partial keyword to the generated code out of the box in a future release of OpenAccess.
If you have Stored Procedures that return types that are not mapped in you data model things get complicated.
You will have to manually create a DTO type for the generated "complex type", mark it as [DataContract], mark all of its properties as [DataMember], then add an assembler - in short recreate manually all the steps that Add OpenAccess Service wizard does for you.

If you need any additional assistance do not hesitate post in our forums.

Regards,
Viktor Zhivkov
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
Patrick
Top achievements
Rank 1
answered on 23 Sep 2013, 10:15 AM
Hi Viktor,

we created a WCF webservice using OpenAccess from Telerik and it works all fine with entities and views.
We are now trying to use some stored procedures but we are not able to create a webmethod to access them as webservices.

What we've done sofar was creating a partial class to extend the EntitiesModelService with a method to call the stored procedure.
We've already created a Domain Method for the stored procedure in the model.

public partial class EntitiesModelService
    {
        [WebGet]
        public IEnumerable<Store> FncGetNearbyPlaces(float? lat, float? lng, float? distance)
        {
            return (new EntitiesModel()).FncGetNearbyPlaces(lat, lng, distance);
        }
    }

and added this line in the EntitiesModelService

public static void InitializeService(DataServiceConfiguration config)
   {
            ...
   config.SetServiceOperationAccessRule("FncGetNearbyPlaces", ServiceOperationRights.All);
 
   }

Hope you can help us to find a solution soon.

Matteo
0
Viktor Zhivkov
Telerik team
answered on 26 Sep 2013, 09:00 AM
Hi Patrick,

Thank you for raising separate thread for your issue.
You can find my answer in your other post at
http://www.telerik.com/community/forums/orm/dsw/wcf-service-with-stored-procedures.aspx
Please us the new forum thread for any further communication.

Regards,
Viktor Zhivkov
Telerik
OpenAccess ORM Q3 2013 Beta is available for immediate download in your account. Get it now and play with the latest bits. See what's new >>
Tags
Getting Started
Asked by
Andrew
Top achievements
Rank 1
Answers by
Viktor Zhivkov
Telerik team
Patrick
Top achievements
Rank 1
Share this question
or