Is there any way to expose the LINQ classes in the SL 2's assembly ? RRS feed

  • Question

  • Having read the SQL Server + LINQ + WCF Webservice + DataGrid tutorial again , I started to consider the following :


    The *.dbml file creates classes based on whatever is exposed to it from the database. Those classes are then used by the data context in the webservice.


    For instance, there's a method : List<Users> GetUsersByLastName(string LastName); It's result is intercepted as e.Result when the call to the webservice is completed. The  Datagrid in the tutorial takes  it as it's itemsource directly : Datagrid.ItemsSource =  e. Result;  . I was wondering, is it possible to  use the List<User > in the assembly containing Silverlight ? How do I expose that type ?



    Monday, May 19, 2008 7:14 AM



    Hello, yes. Take a look at the generated proxy class. You'll find something like this in the End*** method:

    User[] _result = ((User[])(base.EndInvoke("DoWork", _args, result)));

    So e.Result is a User array. Just call e.Result.ToList method will give you a List<User> (require System.LINQ namespace). But be aware that the List<User> in Silverlight assembly is not the same as the List<User> in the WCF service assembly. This is what web service is meant to be. Client and server should share contracts, not data types.

    Wednesday, May 21, 2008 12:42 AM