Search code examples
nhibernatedatabase-first

NHibernate Database-First


I'm putting a front-end together for one of our databases and would like to use NHibernate for it.

Can anyone point out any resources for getting started with Database-first approach? Most tutorials I've seen are for Code/Entity First.

ASP.NET MVC 3 will be my environment, if it matters.

Thanks.


Solution

  • It is all about configuring with NHibernate. As long as Nhibernate is concern, it will not create a database if that is not exists. So you have to configure Nhibernate with the connection string of your existing database in hibernate.cfg.xml(You can also use loquacious api)

    There are lots of configuration possibility in NHibernate; Example includes ConfORM, FluentNhibernate, Configuring With Code, XML.

    For existing database going with xml is often easy. If you choose xml, you can use tools like myGeneration to generate mappings for you.

    As long as you map your object correctly with the existing database nibernate will not complain whether you create your database first or code first. So any intorductory example/application/resource that uses nhibernate as an orm mapper should serve as getting started for you.

    Still there are some techniques you can follow to do database first modeling. Here is a link that may help(code example) Effective Techniques for Database-Driven Modeling

    Here is the Screen Cast Explaining the techniques