Condividi tramite


Developing aN Astoria data provider for SubSonic

I have developed a data provider for SubSonic to enable it as a ADO.NET Data Services data source. This ended up being a bit harder then I initially thought, and is definitely still a work in progress. If you are interested, I have started a code gallery project for it.

I decided to base the first implementation of my provider on SubSonic 3.0 preview 2.  This is the first version of Sub Sonic that supports IQueryable<T> so getting read-only ADO.NET Data Service support over SubSonic is quite trivial. In fact, Jay Kimble has written a very nice post about how to do it here.

To use my SubSonic Astoria data provider, first follow Jay’s instructions to set up your SubSonic DAL.  This includs a very nice addition he has made to the SubSonic T4 templates to automatically add the Astoria attribute for Key properties.

Next, down load the file SubSonicIUpdateable.cs class from the code gallery project. Add it into your project and make it a partial class with the same type as the DB type generated by SubSonic code gen:

 public partial class DB : IUpdatable

Interestingly, SubSonic (at least version 3.0) doesn’t really have a traditional O/R context type per se. In a way, this is practically a requirement for being a Astoria data source. Hence, my implementation utilizes a local context for each set of requests. Since this is only required to support scenarios required by IUpdateable, this was rather trivial to implement.

A few known bugs/ issues with the initial code:

  • Binary fields support is currently not working. Hence inserting/ updating binary data is not happening. I think this is a SubSonic bug, but I need to spend some more cycles looking into it.
  • The IUpdateable implementation currently does not support batch mode. So even if the Astoria client is specifying batching, the DAL will send in the changes one at a time.
  • Only using SubSonic metadata to find primary key properties for a given type for concurrency checks. Probably should switch this to using Astoria metadata for this.
  • Identity values not working. I can’t currently figure out how to get this to work with SubSonic 3.
  • I currently don’t support relationships between entity types because that is not currently supported with the preview of SubSonic.
  • I will try to keep this up to date. Also, along with the code I have included the test project I use to test the implementation.

One other interesting design issue that I discovered while implementing this is how Astoria Data Providers must be integrated at the source level. For example, what I really would like to do is implement something like SubSonicAstoriaProvidr<T> (where T is the DAL instance) and ship a assembly for that. With Astoria V1, that is next to impossible so one has to utilize something like partial classes to make this work. More to come on this later, but this has become one of the most important things we want to improve on in vNext.

Comments

  • Anonymous
    December 05, 2008
    You've been kicked (a good thing) - Trackback from DotNetKicks.com