views:

603

answers:

1

For strongly-typed & type-safe solution, I have to do the following step.

  1. Create some Silverlight application.
  2. Binding input control to Linq data class.
  3. Validate data by using rule from attribute of data class.
  4. Send data to server via WCF.

But, I have some question.

  1. How to bind input control with linq data class property?
  2. How to do that with minimal tiers(layers) and minimal required dll(for Silverlight project)?

PS. .Net RIA Service - May Preview isn't my final answer. Because size of all required dll and some generated code.

Thanks,

+1  A: 

Well, I'm glad you know that .NET RIA Services will provide all of those things but I understand size is a consideration. Keep in mind though, since it looks like you're considering Silverlight 3 you can use the option to cache the framework assemblies to greatly reduce your Xap size:

http://www.wintellect.com/CS/blogs/jprosise/archive/2009/04/06/silverlight-3-s-new-assembly-caching.aspx

I'm not positive that caching applies to the RIA Services assemblies, but if so it would mean they're downloaded only once.

Assuming that's not what you want there are 2 other options to get data from the Linq classes (I'll assume you mean Entity Framework classes) to the client. The most simple method would be to create your own WCF Service as you've mentioned. That way you write data classes on the server and proxy classes automatically get generated on the client that mimic the server classes. The drawback here is business rules won't be shared between the two. So your data validation attributes will need to be written and enforced on the client & the server separately.

The next option is to use ADO.NET Data Services to move the data from the server to the client. This is a step above the previous option in that you won't have to write a WCF service yourself to host the data; it's generated for you. Of course it requires an extra Dll to be packaged in the Xap.

To answer some of your questions directly:

  1. You can't ever bind an input control directly to a Linq data class. You can only bind controls to the client side proxy classes that are generated by referencing a WCF service (either one you wrote yourself or one provided by ADO.NET Data Services).
  2. If you don't use .NET RIA Services you'll need to create a custom attribute to link to your business rules, then handle events on the data bindings manually to read the attribute and enforce your rules.
  3. Use either of the above options to send data to the server - either your own custom WCF Service or ADO.NET Data Services.

Your final question about binding an input control to a property looks like this:

MyControl.xaml.cs:

public MyControl() {
  this.DataContext = new LinqDataClass();
}

MyControl.xaml:
<TextBlock Text={Binding PropertyOnLinqDataClass}/>

Here, LinqDataClass is the client side representation of your server side Linq data class and has a property called PropertyOnLinqDataClass. You'll need to implement the INotifyPropertyChanged interface on the client side to properly support 2 way data binding.

James Cadd
Great answer! But, I don't like caching framework assemblies. Because I can't detect how many percent of loaded assemblies on Silverlight application. At the First time, user must wait long time for complete loading assembly like not responding in Windows application. Do you have any idea to solve this problem?
Soul_Master
You could try creating a custom loading screen:http://msdn.microsoft.com/en-us/library/cc903962(VS.95).aspxUsing that technique you could determine the percentage complete loading the application and notify the user of the progress. Even if the first load takes a long time the user will be notified of the progress. Keep in mind that this is a very simple example - you can make this screen look like anything you want.
James Cadd