Skip to content

Data.Linq.Silverlight

Igor Tkachev edited this page May 20, 2016 · 1 revision

Home / Data / Linq

To enable BLToolkit Linq support for Silverlight you should use BLToolkit.SL.4 project/assembly.

Full dev version of source code contains demo projects Demo\Silverlight for both client and server sides.

Note, Silverlight only use the asynchronous model for all network related calls including WCF. On the other hand, Linq does not contain asynchronous method versions. So, BLToolkit simulates synchronous calls, however if you call Linq methods from main UI thread, you will get deadlock. The following technic should be used instead:

using System;
using System.Linq;
using System.Threading;
using System.Windows.Controls;

namespace Client
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            ThreadPool.QueueUserWorkItem(_ =>
            {
                using (var dm = new DataModel())
                {
                    var q =
                        from c in dm.Categories
                        where  !c.CategoryName.StartsWith("Con")
                        orderby c.CategoryName
                        select  c.CategoryName;

                    var text = string.Join("\n", q.ToList().ToArray());

                    Dispatcher.BeginInvoke(() => OutputText.Text = text);
                }
            });
        }
    }
}
Clone this wiki locally