I’ve been playing with RIAServices and DynamicData lately, and managed to combine these with NHibernate as ORM in an ASP.NET MVC project.
For this project the following (extensive) list of libraries is used (all these libraries are included in the download):
- MS ASP.NET Mvc 1.0
- Microsoft .NET RIA Services July 2009 Preview
- NHibernate 2.1.0CR1
- NHibernate Linq (latest trunk version)
- FluentNhibernate (latest trunk version, patched to work with NHibernate 2.1.0CR1)
- MS Unity 1.2
- ASP.NET Dynamic Data MVC Preview (since this project is pretty old, I had to modify it quite a bit, the source is included in the download)
- I used Rob Conery’s t4 templates as the base to generate entities from the database.
Besides using these libraries, I copied some code snippits from the Kigg project, which has quite a nice codebase!
In the first part of this serie, I’ll show you how you can use these libraries along with my own code to scaffold the entire Northwind database in an mvc project. It’ll be totally hassle-free, I promise! It will generate classes from the database-schema and I will also show you how to override the default generated domainservices and repositories (yes, those are generated at runtime if you don’t specify your own!).
In the upcoming parts, I will add client-side validation and some ajax-love to the scaffold pages. In one of those parts I’ll also explain how my code works, and what it does. I’m also thinking about showing how to replace some parts of the library, since it’s very pluggable. I could for example replace the persistencelayer with Linq-to-Sql or replace the Depency part with StructureMap.
Although this sample shows you how to use an existing database, it would ofcourse be best if you could use the Model-first approach! Luckely nHibernate makes this very simple as well. If you create the entity files in your project and have them inherited from BaseEntity, all you have to do is add this line to your Application_Start:
new SchemaUpdate(IoC.Resolve<Configuration>).Execute(true, true);
Your database schema will be automatically updated if you change anything to your Model.
You can watch the screencast here and download the sample + dll’s here
For the next screencast, I’ll by a mic so I don’t have to subtitle it 😉