Thursday, July 30, 2009

ADO.NET Data Services – 1.5 CTP1

 

Finally got a chance to try out this new preview. Here is a snippet that puts a simplified customers list in an atom feed. This was really quick. The only thing I had to do was to update internet explorer because I was using a XP virtual machine :).

   1: namespace DemoServerSite
   2: {
   3:     public class Customer
   4:     {
   5:         public int ID { get; set; }
   6:         public string Name {get;set;}
   7:         public string Code {get;set;}
   8:         public string Street {get;set;}
   9:         public string Country {get;set;}
  10:         public string PostalCode {get;set;}
  11:         public string FiscalId {get;set;}
  12:     }
  13:  
  14:  
  15:     public class CustomersDataContext
  16:     {
  17:         private List<Customer> source;
  18:  
  19:         public CustomersDataContext()
  20:         {
  21:             source = new List<Customer>();
  22:             source.Add(new Customer {ID=0, Name = "Jose", Code = "C0001" });
  23:             source.Add(new Customer {ID =1, Name = "Maria", Code = "C0002" });
  24:         }
  25:  
  26:         public IQueryable<Customer> Customers
  27:         {
  28:             get
  29:             {
  30:                 return this.source.AsQueryable();
  31:             }
  32:         }
  33:     }
  34:  
  35:     public class WebDataService1 : DataService<CustomersDataContext>
  36:     {        
  37:         // This method is called only once to initialize service-wide policies.
  38:         public static void InitializeService(IDataServiceConfiguration2 config)
  39:         {
  40:             // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
  41:             // Examples:
  42:             config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
  43:             config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
  44:         }
  45:     }
  46: }

This new technology seems to promise because it is really lightweight. Integrates nicely with entity framework and we can tune the behavior by using interceptors. I’ll try to publish some examples of that soon.

Have fun,

No comments: