locked
How to use wcf ria service in Lightswitch application? RRS feed

  • Question

  • Hi

    I want to use WCF RIA service in lightswitch and want to use not only SQL Server but also an oracle database.  How can i use this? 


    maifs
    Monday, July 4, 2011 7:45 AM

Answers

  • My high level summary for getting RIA services working with LS would include the following points (I posted these in another thread as well):

    LS makes consuming RIA services very easy as shown in Michael's tutorial. In fact, easier than creating normal WCF services. Basically you just implement a DomainService class with appropriate methods and LS does the rest. The steps are (using say a Customer and Orders example):

    1. Create your own domain service inheriting from DomainService


    2. For read-only lists of Customers create (Customer objects are just POCOs):
        [Query(IsDefault = true)]
        public IQueryable<Customer> GetCustomers() {}
       
    3. If you need to update Customers you need to implement:
        [Update]
        public void UpdateCustomer(Customer customer) {}
        [Insert]
        public void InsertCustomer(Customer customer)
        [Delete]
        public void DeleteCustomer(Customer customer)
       
    4. A slightly tricky part (when having parent - child relationships) is to override the order in which objects are inserted to ensure parents are inserted before children when the DomainService is called. To do this you override the following method in the DomainService class: protected override bool PersistChangeSet(). When calling the Insert() methods in 3 above you add them to an internal list, order that internal list in this override method and then manually insert them in the correct order (parents first).

    5. Lastly, you need to read up on setting associations between your objects to allow LS to set up the relationships for you. Say you have a Customers and Orders, it would look like this:

    On the Customer class:
            [Association("Customer_Order", "Id", "CustomerId", IsForeignKey = false)]
            public IQueryable<Order> Orders { get; set; }

    On the Order class:
            [Association("Customer_Order", "CustomerId", "Id", IsForeignKey = true)]
            public Customer Customer { get; set; }
           
    Import the domain service into LS as a datasource and go. Can't be easier :)

    You would of course have to implement the domain service methods to talk to Oracle, that should not be that hard.

    Regards


    Xander
    • Marked as answer by Mehmood Ahmed Tuesday, July 5, 2011 9:19 AM
    Monday, July 4, 2011 11:36 PM
  • A good place to start is the MSDN help on RIA Services

    http://msdn.microsoft.com/en-us/library/gg589479.aspx

    The code in Eric Erhardt's article beneath is also very useful in understanding how to build a RIA Service.

    http://blogs.msdn.com/b/lightswitch/archive/2011/04/08/how-do-i-display-a-chart-built-on-aggregated-data-eric-erhardt.aspx

    In Eric's code above, Entity Framework code is used to connect to SQL Server. If you have the Oracle EF Provider installed, you can modify the code here to connect to your Oracle database instead.

    Tim
    • Proposed as answer by Yann Duran Monday, July 4, 2011 11:20 AM
    • Marked as answer by Mehmood Ahmed Tuesday, July 5, 2011 9:19 AM
    Monday, July 4, 2011 8:41 AM
  • This may help:

    Creating a Simple LightSwitch RIA Service (using POCO)

    It will show you the minimum required for a LightSwitch WCF RIA Service.


    http://www.adefwebserver.com

    http://LightSwitchHelpWebsite.com

    • Marked as answer by Mehmood Ahmed Tuesday, July 5, 2011 9:18 AM
    Monday, July 4, 2011 1:12 PM

All replies

  • A good place to start is the MSDN help on RIA Services

    http://msdn.microsoft.com/en-us/library/gg589479.aspx

    The code in Eric Erhardt's article beneath is also very useful in understanding how to build a RIA Service.

    http://blogs.msdn.com/b/lightswitch/archive/2011/04/08/how-do-i-display-a-chart-built-on-aggregated-data-eric-erhardt.aspx

    In Eric's code above, Entity Framework code is used to connect to SQL Server. If you have the Oracle EF Provider installed, you can modify the code here to connect to your Oracle database instead.

    Tim
    • Proposed as answer by Yann Duran Monday, July 4, 2011 11:20 AM
    • Marked as answer by Mehmood Ahmed Tuesday, July 5, 2011 9:19 AM
    Monday, July 4, 2011 8:41 AM
  • This may help:

    Creating a Simple LightSwitch RIA Service (using POCO)

    It will show you the minimum required for a LightSwitch WCF RIA Service.


    http://www.adefwebserver.com

    http://LightSwitchHelpWebsite.com

    • Marked as answer by Mehmood Ahmed Tuesday, July 5, 2011 9:18 AM
    Monday, July 4, 2011 1:12 PM
  • My high level summary for getting RIA services working with LS would include the following points (I posted these in another thread as well):

    LS makes consuming RIA services very easy as shown in Michael's tutorial. In fact, easier than creating normal WCF services. Basically you just implement a DomainService class with appropriate methods and LS does the rest. The steps are (using say a Customer and Orders example):

    1. Create your own domain service inheriting from DomainService


    2. For read-only lists of Customers create (Customer objects are just POCOs):
        [Query(IsDefault = true)]
        public IQueryable<Customer> GetCustomers() {}
       
    3. If you need to update Customers you need to implement:
        [Update]
        public void UpdateCustomer(Customer customer) {}
        [Insert]
        public void InsertCustomer(Customer customer)
        [Delete]
        public void DeleteCustomer(Customer customer)
       
    4. A slightly tricky part (when having parent - child relationships) is to override the order in which objects are inserted to ensure parents are inserted before children when the DomainService is called. To do this you override the following method in the DomainService class: protected override bool PersistChangeSet(). When calling the Insert() methods in 3 above you add them to an internal list, order that internal list in this override method and then manually insert them in the correct order (parents first).

    5. Lastly, you need to read up on setting associations between your objects to allow LS to set up the relationships for you. Say you have a Customers and Orders, it would look like this:

    On the Customer class:
            [Association("Customer_Order", "Id", "CustomerId", IsForeignKey = false)]
            public IQueryable<Order> Orders { get; set; }

    On the Order class:
            [Association("Customer_Order", "CustomerId", "Id", IsForeignKey = true)]
            public Customer Customer { get; set; }
           
    Import the domain service into LS as a datasource and go. Can't be easier :)

    You would of course have to implement the domain service methods to talk to Oracle, that should not be that hard.

    Regards


    Xander
    • Marked as answer by Mehmood Ahmed Tuesday, July 5, 2011 9:19 AM
    Monday, July 4, 2011 11:36 PM