Monday, 11 July 2011

Microsoft Lightswitch and non-Microsoft database

I have been playing around with LightSwitch recently. It works well with ad-hoc database or Microsoft SQL Server. Because we have mostly Oracle as DBMS, that was the first question that I was occupied with, how do I connect it with some other than Microsoft DB?
Well, theoretically there should be two ways to connect to non-MS databases:

  • build a WCF RIA services interface. This approach brings a bit more complexity in the system landscape and weakens the RAD benefits
  • the second one - LightSwitch supports db providers compatible with the entity framework.
I knew three entity framework providers for Oracle:
Progress Software product failed during runtime on showing data. Even after several contact with the customer support and advices from developer team no success on getting it running.

With DevArt dotConnect data could be displayed, but there is no possibility to edit it, so the access is read-only. It must have something to do with transactions handled by the LightSwitch. Digging deeper and trying to customize transaction handling did not bring any positive results.

Recently came out the second beta of Oracle ADO.NET for entity framework, which would actually have been my first test candidate, but the first beta caused my Visual Studio to crash. Nevertheless after successful installation of the ODP.NET beta 2, which is now compatible with the Visual Studio 2010 SP1, the edit buttons in my test LightSwitch application got enabled. A minor tweak is required on the transaction handling and it works as it should! These are the changes required on the data class:

using System.Transactions;  
//  ...  
public partial class MyData_ODPNETService  
{  
     private TransactionScope _tscope;  
     partial void SaveChanges_Executing()  
     {  
          _tscope = new TransactionScope(TransactionScopeOption.Required,  
          new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted });  
     }  
     partial void SaveChanges_Executed()  
     {  
          _tscope.Complete();  
          _tscope.Dispose();  
     }  
}  

No comments: