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

Stored Procedures

1 Answer 64 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.
Keith
Top achievements
Rank 1
Keith asked on 17 Jan 2012, 04:52 PM
Hi

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.

Thanks
Keith

1 Answer, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 20 Jan 2012, 04:37 PM
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.

Greetings,
Petar
the Telerik team

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

Tags
Getting Started
Asked by
Keith
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Share this question
or