13
ASP.NET MVC, DynamicData, Domain-/RiaServices, Unity and NHibernate: Part 1
Posted in asp.net mvc, nhiberntate, RiaServices, unity by Chris van de Steeg
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
12 Responses to “ASP.NET MVC, DynamicData, Domain-/RiaServices, Unity and NHibernate: Part 1”
Parag Mehta says:
Jul 27, 2009
Excellent! Just a question : what software you used to create the screencast ? I am not native english speaker, so interested in how you subtitled the screencast
.
Great screencast, waiting for more iterations…
Jimit Ndiaye says:
Oct 31, 2009
Wow! This is some of the coolest stuff I’ve seen in a while! Keep it coming! Now if only the REST model for RIA domain services could be consumed remotely, I’d be saying goodbye Astoria.
Atam says:
Nov 25, 2009
Hi Chris, nice work. I’m also from the Netherlands (Hoofddorp).
Something is bothering me. Its is nice to see a well thought framework using NHibernate and Riaservices, business rules ect. The problem for me is, that i build an alike framework (also using NHibernate as possible DAL) and RiaServices, but i want to use Silverlight.
The problem then becomes that Silverlight generates client side proxies. If your domain object properties have code for validation ect you will lose that. Also Silverlight can only refer to Silverlight projects/assemblies.
So i was wondering if you have tried using above code with Silverlight instead of MVC.
Thanks in advance.
Sean says:
Dec 5, 2009
Thanks Christ! great presentation. and now the new version of MVC and RiaServices are out. would you be interested to update your demo to take advantage of the vs2010?
cheers
Daniel says:
Apr 18, 2010
Wow man… That is really nice!!!
I would like to know if there is a way to use Silverlight as the View, using the services published by Ria Services?
But, really, really cool!!!
Daniel says:
Apr 18, 2010
One more question… is about the lazy loading from Nhibernate… is it active or not?
Chris van de Steeg says:
Apr 23, 2010
@all: sorry for the lack in updates and response.
Will try and pick up where I left soon
Sanjay says:
May 17, 2010
Thanks for the post Chris. I am also interested in using NHibernate + RIA with Silverlight. Could you please throw some light on it?
Felicita Chhon says:
Jun 3, 2011
Hey, I really don’t think saying this on your post ASP.NET MVC, DynamicData, Domain-/RiaServices, Unity and NHibernate: Part 1 | Chris van de Steeg would be the correct place however I wasn’t able to locate a contact page within your somewhat messy theme (sorry). My visitors would always tell me the exact same thing so I converted to a new theme from http://tinyurl.com/themeforestz. I have only gotten kind comments since. Cheers, Felicita Chhon
2 Trackback(s)
- Jul 27, 2009: 9eFish
- Oct 26, 2009: Exploring MVC architecture | Softwarefun
