.NET RIA and You!

So MS just released their .NET RIA code for consumption. I’ve talked a bit about this in the MIX 09 presentation we did before, but I’d like to go over it a bit more in depth. Although it’s targeted towards webdevs who don’t want to mess around with transport objects and the like, there is potential for us to use it as well I think. Here’s a quick overview of the capabilities:

Domain Services – binds to a DataContext (LINQ, ADO.NET ES) and exposes CRUD methods automatically via an automatically generated DomainContext class in your client. The DomainContext class behaves very similar to LinQ context classes, i.e. context.Customers returns the contents of the customer table. Pretty straightforward stuff.

Controls that Support Domain Contexts – Some controls such as the Grid in XAML will consume a DomainDataSource and provide automatic select, order by, and paging functionality without having to wire anything up.

Metadata Validation – when the Domain Service creates all the classes required by your data source and context, it creats Metadata classes for each data entity in the source. You can then specify Validation Attributes on those server-side classes that will transfer to the client and can be used client-side for validation, such as [Required(ErrorMessage=“This field is required”)] or [StringLength(30, “Customer’s name cannot be more than 30 characters”)], or if wanna get fancy, [RegularExpression(@“^[A-Z0-9._%+–]+@[A-Z0-9.–]+.[A-Z]{2,4}$”, ErrorMessage=“Please provide a valid email address”)]. Some client-side controls (such as DataForm) will automatically consume and apply these validations, meaning we don’t have to write a line of code. In future releases of .NET RIA they’ll even pull these validations directly from the data source definitions.

Shared Server Code – you can specify classes & code in your app tier, and have the client automatically consume that code by simply marking it with the [Shared] attribute. Any client that has a reference to your app-tier will automatically generate code on the client side to reference the server-side code, and your client-side code won’t know the difference. This is primarily used for custom validations, but technically can do anything you want. Example:

‘’‘ csharp Server-side class [Shared] public class CustomerValidation { [Shared] public static bool IsEmailEndsWithDotCom(string email) {

if (email.EndsWith(".com"))
  return true;
return false;

} } ‘’‘ ’‘’ csharp Client-side code private void Page_Loaded(object sender, EventArgs e) { CustomerValidation.IsEmailEndsWithDotCom(tbEmail.Text); } ‘’’