ADO.Net Data Services Feedback: DataContextServiceProvider Required for LINQ to SQL support

20 בדצמבר 2007

ADO.Net Data Services Feedback: DataContextServiceProvider Required for LINQ to SQL support

After writing my previous posts about ADO.Net Data Services:

I took a little time to write some logic that manipulates data on the client side and applies the changes back to the service.

Starting with adding a new entity:

BlogDataContext ctx = new BlogDataContext("http://localhost:2445/BlogData.svc");

 

Blog blog = new Blog { BlogID = "guy.burstein", BlogName = "My new Blog", Owner = "Guy Burstein" };

ctx.AddObject("Blogs", blog);

 

ctx.SaveChanges();

I got a WebException: "The remote server returned an error: (400) Bad Request.", which means that the Data Service cannot handle my request to add a new entity.

Digging with reflector, I had some insights about the process being taken when the Data Service is being initialized when a request needs to be processed:

public class BlogData : WebDataServiceSomeDataContextHere  >

{

   …

}

According to the context being provided as the generic argument for the WebDataService class, an appropriate IWebDataServiceProvider is being created.

IWebDataServiceProvider provider = WebDataService<T>.CreateProvider(dataServiceType);

The CreateProvider method check if the dataServiceType is an ObjectContext (Entity Framework context) and creates an ObjectContextServiceProvider. Else, it creates a ReflectionServiceProvider.

if (typeof(ObjectContext).IsAssignableFrom(c))

{

    provider = new ObjectContextServiceProvider(c);

}

else

{

    provider = new ReflectionServiceProvider(c);

}

In order for a data service to be updatable, one of the following must exist:

  • The service context implements IUpdatable, or
  • The related WebDataServiceProvider implements IUpdatable.

The ADO.Net Entity Framework's ObjectContext does not implement IUpdatable, but its ObjectContextServiceProvider does, so building a Data Service with an ObjectContext gives you an update support out of the box. Using LINQ to SQL with a DataContext on the other hand, results in using the ReflectionServiceProvider that has no built in support for IUpdatable operations, and it relies on the data service context to implement it.

Conclusion

Using ADO.Net Entity Framework as the service data context gives you update support for free. If you are using LINQ to SQL, you can implement IUpdatable yourself, as Mike has done here. I think that the product team should consider adding a DataContextServiceProvider class that uses the LINQ to SQL DataContext capabilities for updating the store.

Add comment
facebook linkedin twitter email

3 comments

  1. Roger Jennings21 בדצמבר 2007 ב 21:04

    +1 on the request for the DataContextServiceProvider, but I believe that it took a lot of pushing and pulling to open up Astoria to data providers other than EF.

    –rj

    Pingback from http://oakleafblog.blogspot.com/2007/12/linq-and-entity-framework-posts-for_20.html

  2. krkivcypkt12 בינואר 2008 ב 13:01

    nmssrK uythahgjxahl, [url=http://puqmzyamrkzx.com/]puqmzyamrkzx[/url], [link=http://ltvniteskgas.com/]ltvniteskgas[/link], http://zcumpoebzgfj.com/

Comments are closed.