Stored Procedures

2 posts, 0 answers
  1. Keith
    Keith avatar
    88 posts
    Member since:
    May 2007

    Posted 17 Jan 2012 Link to this post


    Sorry if I've missed something obvious but is it possible to use SPs (rather than views / tables) to return information from the database (not just a set of results from a single table) and have these available via RIA Services? I can see that I can map the results to a Complex Type but these are not recognized by the RIA wizard.

    I understand that a key is required in the resultset (from getting this working with EF) but I can't seem to get my custom MetaData to be recognised.


  2. PetarP
    PetarP avatar
    754 posts

    Posted 20 Jan 2012 Link to this post

    Hi Keith,

     Basically you shouldn't have any problems returning the result of a stored procedures via your RIA service. What you need to do is expose it like you normally do with your other endpoints. So for example if your stored procedure returns customers then you will need to add the following: 

    public IQueryable<Customer> GetCustomersByID(string id)
          return this.DataContext.GetCustomersByID(id).AsQueryable<Customer>();
    Please note that in some cases the data services themselves cannot correctly "guess" the primary key of the object you are returning. In that case you will need to go to your persistent class and mark its primary key with the [Key] attribute. 
    I hope this helps. Please do not hesitate to contact me back should you have any further problems.

    the Telerik team

    SP1 for Q3’11 of Telerik OpenAccess ORM is available for download

  3. DevCraft banner
Back to Top