Connect to Microsoft LightSwitch OData service
This guide demonstrates how to connect to Microsoft LightSwitch OData service, for complete database migration please visit Migrating from LightSwitch article.
Connect to data
Similar to Microsoft LightSwitch, Radzen can connect to various data sources including OData services V3 and V4, Microsoft SQL Server, MySQL, PostgreSQL, Oracle, Swagger or pure REST service.
In Radzen however you have ability to work not only with tables and views in case of Microsoft SQL Server but to call stored procedures for SQL Server 2012 and above.
The other major addition in Radzen is the automatic CRUD pages creation directly from your data. This feature will cut dramatically your developement time and will help you to build fully functional database administrative application in minutes. Radzen will read all database relations and will create lookups, cascading deletes, etc. automatically.
Of course you can skip this step, just infer the data and construct desired pages manually similar to Microsoft LightSwitch
Creating pages manually
Again similar to Microsoft LightSwitch, Radzen can create set of pages for read, edit and add records for desired database table.
Unlike Microsoft LightSwitch in Radzen you have powerful visual designer to fine-tune and customize easily your page UI.
Creation of completely empty pages is also avaialable and you can later drag & drop, bind and customize desired UI. For more info please visit Create, Edit and Delete articles in our documentation.
Consuming data from existing Microsoft LightSwitch application
Radzen can consume data and build automatically UI from your existing Microsoft LightSwitch application.
Add CORS compatibility to the Global.asax file in your LightSwitch server application.
protected void Application_BeginRequest(object sender, EventArgs e)
{
var res = HttpContext.Current.Response;
var req = HttpContext.Current.Request;
res.AppendHeader("Access-Control-Allow-Origin", (req.Headers["Origin"] == null ? "*" : req.Headers["Origin"]));
res.AppendHeader("Access-Control-Allow-Credentials", "true");
res.AppendHeader("Access-Control-Allow-Headers", "Content-Type, X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Date, X-Api-Version, X-File-Name, MaxDataServiceVersion, DataServiceVersion, If-Match, Authorization");
res.AppendHeader("Access-Control-Allow-Methods", "POST,GET,PUT,PATCH,DELETE,OPTIONS");
// ==== Respond to the OPTIONS verb =====
if (req.HttpMethod == "OPTIONS")
{
res.StatusCode = 200;
res.End();
}
}
Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim res = HttpContext.Current.Response
Dim req = HttpContext.Current.Request
res.AppendHeader("Access-Control-Allow-Origin", (If(req.Headers("Origin") Is Nothing, "*", req.Headers("Origin"))))
res.AppendHeader("Access-Control-Allow-Credentials", "true")
res.AppendHeader("Access-Control-Allow-Headers", "Content-Type, X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Date, X-Api-Version, X-File-Name, MaxDataServiceVersion, DataServiceVersion, If-Match, Authorization")
res.AppendHeader("Access-Control-Allow-Methods", "POST,GET,PUT,PATCH,DELETE,OPTIONS")
If req.HttpMethod = "OPTIONS" Then
res.StatusCode = 200
res.[End]()
End If
End Sub
Run LightSwitch application, copy the first part of the URL (http://localhost:#####/
) of your running app and add LightSwitch data-source name and .svc
at the end. The final service URL should be similar to http://localhost:64052/NorthwindData.svc/
.
Create new OData data-source in Radzen and set this URL as REST endpoint.
Run Radzen app to check the result.
LightSwitch OData service is V3 and relationships data is limited. Radzen will unable to retrieve and build automatically lookup fields, cascading deletes, etc. You can add this information manually in Radzen application folder
meta/data/[DATA-SOURCE-NAME].json
file. For example Northwind Customers <-> Orders:
...
"Customer": {
"properties": {
"CustomerID": {
"type": "string",
"x-key": true,
"x-navigation": [
{
"inversePropertyName": "Customer",
"name": "Orders",
"type": "Order"
}
]
}
...
"Order": {
"properties": {
"CustomerID": {
"type": "string",
"x-foreignKey": {
"name": "Customer",
"parentEntityType": "Customer",
"parentTable": "Customers",
"principalKey": "CustomerID",
"textProperty": "CompanyName",
"type": "Customer"
},
"x-key": false
},
...
For more info please visit OData article in our documentation.
LightSwitch service basic authorization
LightSwitch application can be published with Forms authentication
and to connect to such application service you can use Basic authorization
Important! If your LightSwitch service is protected by Windows authentication please check Send user credentials (required for services protected by Windows authentication) during infer.