SQL Server CE – Great for prototyping and testing
Yesterday I put together a simple POC app for my team lead who needed to see Spring.NET + NHibernate in action (no, not the book) for a client. Even though these days I’m using the Castle stack for most of my IoC/DI and mini-framework needs, it was interesting to see how far Spring.NET has come (probably more on that in future posts…) since I last used it a long time ago.
I had a very basic scenario I focused on; adding and retrieving employees with a first and last name. I started out with a basic web app, service and repository. I just created a simple EmployeeService class that took in an implementation of IEmployeeRepository via its constructor. I ended up creating 4 different implementations of an IEmployeeRepository, for testing out different scenarios and used Spring.NET to inject the appropriate one into my service.
I started out with no help from Spring.NET or NHibernate regarding repositories and just created a simple in-memory repository implementation which just stored the data in a private IList
In Comes SQL Server CE
So I’ve been wanting to try SQL Server CE anyway, so I went ahead and downloaded it. I created another repository implementation that just used plain ol’ ADO.NET using the System.Data.SqlServerCe assembly. As you can see, it’s very easy to set up the SQL Server CE engine…
Then I created yet another repository implementation, this time one that leveraged NHibernate, which has built-in support for SQL Server CE. Instead of setting up a config file for NHibernate, I took a chapter out of Ayende‘s Rhino Commons and configured NHibernate all from code…
This all worked great and I was very pleased at how quickly I was able to get all of this up and running.
So all of my integration tests worked like a champ so I go and wire up Spring.NET to use one of my new SQL Server CE enabled repositories and fire up my web app and get a nice little YSOD with this…
“SQL Server Compact Edition is not intended for ASP.NET development”
Seemed a little strange to me, but Steve Lasker tries to explain why. Luckily, it’s easy enough to workaround. Just place this line of code before any code that starts mucking around with SQL Server CE…
Anyway, guess that’s it for now.