Monday, January 14, 2013

Creating a RIA Services Solution With VS 2012


To set up a RIA Services solution

  1. Create a new RIA Services project in Visual Studio 2012 by selecting FileNew, and then Project.
    The New Project dialog box appears.
  2. Select the Silverlight Application template from Silverlight group of the Installed Templates and name the new project RIAServicesExample.
    Click OK.
    1. The New Silverlight Application dialog box appears.
    2. Select the Enable WCF RIA Services check box near the bottom of the dialog box. Checking this box creates a RIA Services link between the client project and the server project.
      3. Click OK to create the solution.
      The solution contains two projects: a client project and a server project. The client project is named RIAServicesExample and it contains the Silverlight code that you use to create the presentation tier. The server project is named RIAServicesExample.Web and it contains the middle-tier code.
      4. Add Edm to your project by graphical interface and set the name default

      5. Generate your entity model
      6.Choose Connection string by this way
      7. Set Data Base Name
      8. Select Sql Server
       9. Choose Radio button yes and press next button
       9. Select Data Base Table or Sp
       10.Delete the two “.tt” generated files in the entity model
      11.Open your entity model in the designer and change Code Generation Strategy from "None" to "Default"
      12.Rebuild the project and Now you can add a new Domain Service
       13.Check Like as image

      14.Rebuild your solution and add code to MainPage.xaml page

       15.Add the Following code into MainPage.cs Page
       16.Build your Solution and Run,now you can see data look like as
      17.Thank you




2 comments:

  1. Hello, how can i call a Store Procedure with the connection? Thank You!

    ReplyDelete
  2. Open your entity model and go to properties and choose 'Update Model From DataBase', now you can see your sp, add sp and rebuild your solution. now you will create class like

    public class Extension
    {
    public Customer SetToBusinessObject(spGetAllCustomers_Result result)
    {
    var bobject = new Customer
    {
    CustomerID = result.CustomerID,
    CompanyName = result.CompanyName,
    City = result.City,
    Country = result.Country
    };

    return bobject;
    }
    }

    and create method to your customer service like

    public IQueryable GetAllCustomers(string CustomerID)
    {
    var customerList = this.ObjectContext.spGetAllCustomers(CustomerID).ToList();
    var List = customerList.Select(c => new Extension().SetToBusinessObject(c)).ToList();
    return List.AsQueryable();
    }

    and you can call your sp from view model or page code behind
    like below

    cusContext.Load(cusContext.GetCustomersQuery(customerID), GetAllCustomersCallBack, null);

    and call back funtion

    private void GetCustomersCallBack(LoadOperation customer)
    {
    if (customer.Entities == null || customer.HasError) return;
    dataGrid.ItemsSource = customer.Entities;
    }

    i think it is useful to you thanks.

    ReplyDelete