New Posts New Posts RSS Feed: Using Stored Proc in MVVM Light example
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Using Stored Proc in MVVM Light example

 Post Reply Post Reply
Author
Delta_Rich View Drop Down
Newbie
Newbie
Avatar

Joined: 19-Oct-2011
Location: NZ
Posts: 10
Post Options Post Options   Quote Delta_Rich Quote  Post ReplyReply Direct Link To This Post Topic: Using Stored Proc in MVVM Light example
    Posted: 25-Apr-2013 at 4:24pm
I have watched and followed the video "MVVM Light with DevForce (Silverlight)", which was a great help. Now I am stuck with how to utilise the "Function Import" of a stored procedure returning a list of Entities.

If for example (from the example above) I create a Stored Proc that retrieves Customers where Country = parameter 1 and Region = parameter 2
(obviously this could be done using Linq but I want to show this as an example of parametised sprocs).
eg SQL would "EXECUTE usp_CustomerCtyReg 'USA', 'OR'"

In my dataservice I would try it this way - varying from the video example by calling the LoadCustomersViaSPQuery:

public void LoadCustomersViaSPQuery( Action<IEnumerable<Customer>> success = null, Action<Exception> fail = null)
{
     // Call the StoredProc for this
     Manager.RetrieveSPCustomersQuery(pCountry: "USA", pRegion: "OR")
          .ExecuteAsync(op =>
     {
          if (op.CompletedSuccessfully)
          {
               if (null != success)
               {
                    success(op.Results);
               }
          }
          else
          {
               if (null != fail)
               {
                    op.MarkErrorAsHandled();
                    fail(op.Error);
               }
          }
     });              
}



However, the success(op.Results) is erroring - "Delegate .... has some missing arguments."

Once I sought that out I imagine (and probably incorrectly) the ViewModel should just follow the remainder of the example.

Anyhow, can someone please provide me with the "how to" based on the video example?
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 26-Apr-2013 at 10:42am
A StoredProcQuery when executed returns an IEnumerable, so if you cast the op.Results to an IEnumerable<Customer> this should work:

success(op.Results.Cast<Customer>());

You'll need a using statement for System.Linq too.
Back to Top
Delta_Rich View Drop Down
Newbie
Newbie
Avatar

Joined: 19-Oct-2011
Location: NZ
Posts: 10
Post Options Post Options   Quote Delta_Rich Quote  Post ReplyReply Direct Link To This Post Posted: 28-Apr-2013 at 8:15pm
Yep that got it.
Thanks
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down