Tuesday, January 20, 2009

ADO.NET Data Service

If you use LINQ, you'll definitely like ADO.NET Data Services. It lets you perform LINQ queries remotely so your database can be with a web server behind a firewall, and the client can access the database through the web server.

The ADO.NET Data Service is a class that inherits from a DataService generic class (the context class is used for the generic type). Example:
public class WebDataService : DataService<NitinEntities>

The InitializeService method is used to set access privileges. Example:
public static void InitializeService(IDataServiceConfiguration config)
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);

You can add additional methods that return the IQueryable generic type. Think of them as the equivalent of views over tables.

The client application needs to have a service reference. After adding the reference, you'll find a context class (WebDataService.NitinEntities) that you can use. You can run LINQ queries over the context remotely.

No comments: