R – the equivalent of LINQ-to-SQL for Silverlight

data-access-layerlinqsilverlightwcfwcf-ria-services

I have a WPF application that uses LINQ-to-SQL on a local .MDF file. This solution is simple, easy, and effective, i.e. I set up my model once, then read/write data anywhere via LINQ:

        using (var db = Datasource.GetContext())
        {
            oldItem = (from i in db.Infos
                       where i.Id == TheId
                       select i).SingleOrDefault();
            CreateForm(db, FormBase, oldItem, Button_Save);
        }

What is the dead-simple equivalent of this for Silverlight apps?

Searching I find an explosion of terms:

  • WCF RIA Services, WCF Data Services (ADO.NET Data Services, Astoria), Data Services Toolkit
  • .NET RIA Services
  • OData(Dallas)
  • GData
  • REST, REST-based, REST-like, REST-inspired
  • XML, JSON, RDF+XML
  • web services, SOA
  • cloud-based services, Azure, SQL Azure, Azure Services Platform

All I want to do is this:

  • create an .mdf file
  • use some LINQ-to-SQL-like tool to generate a web-enabled (REST?) data layer etc.
  • ftp the .mdf file and classes up to my ASP.NET web hosting service
  • write silverlight clients that read and write to this data source with LINQ

Best Answer

Concentrate on learning RIA Data Services, or WCF Data Services. It converts your LINQ queries inside Silverlight to REST requests, and saves you from writing some of the infrastructure code. The whole idea is that your SL app communicates only to web services, you don't have access to physical DB, like when you're using some ORM (L2S). In SL, your are inside browser's sandbox, which prevents you from accessing file system, including db files.
Other approach is to write web service and expose data through it (GetArticleByID), and then you consume that services from Silverlight. Then you use LINQ to iterate on fetched, loaded data.

Related Topic