DCSIMG
ADO.Net Data Services Feedback: DataContextServiceProvider Required for LINQ to SQL support - Guy Burstein's Blog

Guy Burstein's Blog

Developer Evangelist @ Microsoft

News

Guy Burstein The Bu

Disclaimer
Postings are provided 'As Is' with no warranties and confer no rights.

Guy Burstein LinkedIn Profile

TwitterCounter for @bursteg

Links

Articles

Blogs I Read

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

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.

Comments

Adiel said:

you can see a sample in here

mtaulty.com/.../10031.aspx

# December 21, 2007 5:04 AM

Roger Jennings said:

+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 oakleafblog.blogspot.com/.../linq-and-entity-framework-posts-for_20.html

# December 21, 2007 9:04 PM

krkivcypkt said:

nmssrK <a href="uythahgjxahl.com/.../a>, [url=http://puqmzyamrkzx.com/]puqmzyamrkzx[/url], [link=http://ltvniteskgas.com/]ltvniteskgas[/link], http://zcumpoebzgfj.com/

# January 12, 2008 1:01 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: