Execute Stored Procedure in WCF RIA Services

5 May

WCF RIA Services amazing! I use it in a several Silverlight projects and keep getting amazed.

Today I got a question about retrieving data from a Stored Procedure in Silverlight using WCF RIA Services and a LINQ-to-SQL datamodel.

The LINQ-to-SQL datamodel in this sample contains a table called Book and a stored procedure called GetBooks. The stored procedure returns a list of books from the Book table and it is attached to the datamodel.


I have created a domain service that use the datamodel to return data to the Silverlight client. In the service I have created a method called GetBooks – it returns an ObservableCollection of Books.


The stored procedure return an ISingleResult of GetBooksResult. I have tried to convert the result to an ObservableCollection without success (any ideas?). To fix this issue I loop the result and add the items to a new ObservableCollection.

Finally, on the Silverlight I call my domain service (_context) and invoke the GetBooksQuery method to get the result.


I got inspiration from this blog post by Scott Gu.

by xamlgeek

2 Responses to “Execute Stored Procedure in WCF RIA Services”

  1. Les Prigmore August 13, 2010 at 22:07 #

    RIA Service & Stored Procedure & Function Import & Include(Navigation Property) in a DomainService

    Hi, I am trying to use the technology above with, of course, Silverlight 4 and VS2010.

    There is a table “tblMyType” in the EDM, a stored procedure “sp_MyType” that returns rows and a function import “fi_MyType” that maps “sp_MyType” to “tblMyType”. That works fine, but when I try to use .Include(“myNavigationProperty”),

    I get a squiggly underlining “.Include(“myNavigationProperty”)” and the following error message:
    ‘System.Data.ObjectResult’ does not contain a definition for ‘Include’ and no extension method ‘Include’ accepting accepting a first argument of type ‘System.Data.ObjectResult’ could be found (are you missing a using directive or an assembly reference?).
    The code from the DomainService is below:
    public IQueryable GetTblMyTypeById(Int64 MyTypeId)
    // the following code was generated by the DomainService template.
    //return this.ObjectContext.tblMyTypes;

    // I want to replace the generated code with the following code:
    return this.ObjectContext.fi_SelectMyType()
    .Where(m => m.MyTypeId == MyTypeId);

    I really need the “include” because the combo boxes won’t work without it.
    If I can’t solve this problem, the boss says I have to abandon RIA Services for this project and really don’t want to do that. Does anyone know how to get around this problem?
    If I have to abandon RIA Services, is anyone aware of any similar, or any, problems with WCF DataServices?
    Thanks in advance for any help or direction…..Les


  1. 2010 in review « xamlgeek - January 3, 2011

    […] Execute Stored Procedure in WCF RIA Services May 2010 1 comment 3 […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: