ASP.NET MVC, DynamicData, Domain-/RiaServices, Unity and NHibernate: Part 1

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):

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 😉