Answered by:
RIA Service or OData service

Question
-
Starting a new LS application where I want to try the new version.
The data source was going to be a custom RIA Service wrapped around an existing large application. With the new version of LS having embraced OData, seemingly in the same way as RIA Services were embraced in LS V1, I'm wondering whether I should instead be creating this custom data source as an OData data source instead?
Presumably one can only create an OData data source inside LS if you base that on an underlying database, rather than trying to wrap an existing application. To that extent one would probably have to use WCF Data Service instead to create such an OData data source.
Questions I'm pondering:
1. Should we rather use OData in the next LS version where we used RIA services in the previous version?
2. If so, would we indeed us WCF Data Services to create that or could we use the new ASP.NET Web API?
Thoughts
Xander
- Changed type Eric ErhardtMicrosoft employee, Moderator Friday, March 9, 2012 6:10 PM Questions are asked in the post. Making this a question.
Friday, March 9, 2012 3:14 AM
Answers
-
Xander,
You can rest assured that since we allowed you to connect to a custom Ria Service in v1 and v2, you will be able to bring any investment you made in those custom Ria Services forward. So I wouldn't worry that because we are embrassing OData as our public protocol that you shouldn't use WCF Ria Services as a custom data source when it makes sense.
A couple considerations:
- Making a WCF Ria Service is relatively simpler than making a custom OData service, in my experience.
- When using WCF Ria Services, LightSwitch will invoke it in-memory on the web server. When attaching to an OData service, the web server will always make an Http request to the OData service. So there are performance considerations here because an attached OData service will require another "hop" from your web server to your OData service.
- If you were to make an OData service, you need to handle deploying it yourself. But if you have a WCF Ria Service, LightSwitch will deploy the assembly with your LightSwitch application and they will be hosted in the same web application.
So my simple answer for #1 is "usually no". Still make use of Custom Ria Services in v2 as you would have in v1. There my be extraneous circumstances where this doesn't alway hold, but by default I would still use Ria.
To answer #2, ASP.Net Web API builds REST services. OData is a type of REST service, but not all REST services are OData. I've never tested attaching LightSwitch to a REST service built by ASP.NET Web API, but since it isn't strictly an OData service, I wouldn't assume it would work. You would need to use WCF Data Services or some other OData framework to make an OData service for LightSwitch to consume.
- Proposed as answer by Eric ErhardtMicrosoft employee, Moderator Friday, March 9, 2012 6:11 PM
- Marked as answer by novascape Friday, March 9, 2012 10:46 PM
Friday, March 9, 2012 6:10 PMModerator
All replies
-
Hi Xander,
Any data source that you can connect to via LightSwitch is exposed as an OData service, which can then be consumed by LightSwitch or any other application that can consume OData. So, for example, if your large application is based on a SQL database, you can easily use LightSwitch to create OData feeds for the SQL database and use LightSwitch's capabilities such as authentication and filtering of data to control those feeds.
LightSwitch isn't just for creating applications anymore, it's by far the easiest way to expose and control access to data via OData. Of course, if OData isn't an option in your situation, RIA services are still a perfectly viable option. So, 1. Maybe, depends on your requirements, and 2. No, LightSwitch is all that you need.
It blew my mind when I realized the potential of exposing LightSwitch data as OData - it opens up numerous possibilties.
Thoughts?
Regards,
Steve Hoag Microsoft aka the Lights Witch (IEnumerable of Newt)
- Proposed as answer by Marcelo111 Tuesday, March 13, 2012 11:30 PM
Friday, March 9, 2012 8:12 AMModerator -
Xander,
You can rest assured that since we allowed you to connect to a custom Ria Service in v1 and v2, you will be able to bring any investment you made in those custom Ria Services forward. So I wouldn't worry that because we are embrassing OData as our public protocol that you shouldn't use WCF Ria Services as a custom data source when it makes sense.
A couple considerations:
- Making a WCF Ria Service is relatively simpler than making a custom OData service, in my experience.
- When using WCF Ria Services, LightSwitch will invoke it in-memory on the web server. When attaching to an OData service, the web server will always make an Http request to the OData service. So there are performance considerations here because an attached OData service will require another "hop" from your web server to your OData service.
- If you were to make an OData service, you need to handle deploying it yourself. But if you have a WCF Ria Service, LightSwitch will deploy the assembly with your LightSwitch application and they will be hosted in the same web application.
So my simple answer for #1 is "usually no". Still make use of Custom Ria Services in v2 as you would have in v1. There my be extraneous circumstances where this doesn't alway hold, but by default I would still use Ria.
To answer #2, ASP.Net Web API builds REST services. OData is a type of REST service, but not all REST services are OData. I've never tested attaching LightSwitch to a REST service built by ASP.NET Web API, but since it isn't strictly an OData service, I wouldn't assume it would work. You would need to use WCF Data Services or some other OData framework to make an OData service for LightSwitch to consume.
- Proposed as answer by Eric ErhardtMicrosoft employee, Moderator Friday, March 9, 2012 6:11 PM
- Marked as answer by novascape Friday, March 9, 2012 10:46 PM
Friday, March 9, 2012 6:10 PMModerator -
You can rest assured that since we allowed you to connect to a custom Ria Service in v1 and v2, you will be able to bring any investment you made in those custom Ria Services forward.
Friday, March 9, 2012 6:38 PM -
Thanks Eric and Steve for the information, this is very helpful and informative indeed and I think I will keep that particular service as a custom RIA service for now. I do have other areas where I will experiment with the new OData capabilities in V2.
I have another couple of hopefully simple related questions:
1. I will test this very soon for myself, but I assume that now we can create relationships inside the same container in V2 that we can declare relationships between entities for a custom RIA data service as well? If that is the case it will be very cool indeed!
2. Assuming the answer is Yes to the above question, in V1 we had to implement special logic in the RIA domain service (overriding the PersistChangeSet() method) to ensure that parents always get inserted before children (when inserting master/detail records from the same LS screen). Since this is not a problem when using native LS data source (LS takes care of that for you) will this special logic still be required in a custom RIA domain service if the relationships are defined inside LS V2?
Thanks
Xander
Friday, March 9, 2012 10:46 PM -
2. Assuming the answer is Yes to the above question, in V1 we had to implement special logic in the RIA domain service (overriding the PersistChangeSet() method) to ensure that parents always get inserted before children (when inserting master/detail records from the same LS screen). Since this is not a problem when using native LS data source (LS takes care of that for you) will this special logic still be required in a custom RIA domain service if the relationships are defined inside LS V2?
Thanks
Xander
I suspect the answer is no. From what I can tell with OData you operate on one entity at a time:
http://www.kashyapas.com/2011/06/05/performing-crud-on-odata-service-using-datajs/
OData has a $batch process, but it appears you have to submit everything yourself... manually:
http://www.odata.org/developers/protocols/batch
Friday, March 9, 2012 11:02 PM -
Thanks Michael, but I was meaning with a RIA service rather than an OData service. Interesting to know about the single & batch operations with OData though.
Thanks
Xander
Friday, March 9, 2012 11:05 PM -
Thanks Michael, but I was meaning with a RIA service rather than an OData service. Interesting to know about the single & batch operations with OData though.
Thanks
Xander
Opps sorry.
However, when you have a custom WCF RIA Service in LightSwitch you_are_on_your_own (your service talks to the EF (Entity Framework) class directly) so I would be surprised if that changed... unless they fixed something in EF.
Friday, March 9, 2012 11:19 PM -
To answer #1, unfortunately no, you can only define relationships inside the same container in V2 against database backends. For SharePoint, OData and Custom Ria, the backend needs to identify the relationship for you to use it in LightSwitch.
If you control the WCF Ria Service, you can add [AssociationAttribute] attributes to the navigation properties in the Ria service and LightSwitch will be able to consume those relationships. See http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/353c6adb-a5c1-4a58-a58c-f580b584f534 and the related blog post: http://blogs.msdn.com/b/lightswitch/archive/2010/10/22/how-to-create-a-ria-service-wrapper-for-odata-source.aspx for more info on how to add the AssociationAttribute to define relationships in Ria Services.
Friday, March 9, 2012 11:20 PMModerator -
Thursday, April 19, 2012 5:50 AM