NHibernate Database-First - nhibernate

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.

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

please take a look at this: http://www.devart.com/entitydeveloper/nhibernate-designer.html it is not a freeware.
There is another open source tool which was referred in another question long time back. here is the link: http://www.mygenerationsoftware.com/phpBB2/viewtopic.php?t=1505
btw are you planning to use fluent nhibenrate or just nhibernate?
On a side note: Entity Framework supports a database-first approach with an integrated designer for Visual Studio. This designer produces an XML file (EDMX) that describes the required mappings.
Note: I am not marketing any of these products.

Related

Use RavenDB as the database for an Orchard CMS module

I'm just getting underway with Orchard CMS. How difficult would it be to create an Orchard module that uses RavenDB as its database? Is a hard dependency on SQL and NHibernate baked deeply into Orchard?
All of Orchard's core features are based on NHibernate so it would be difficult to move the entire Orchard database to another DBMS not supported by NHibernate. However, Orchard is very extensible and it is quite easy to access all kinds of custom data sources from your own modules. For example, I am currently working in a project where we store our data in a graph database (neo4j) and access them in Orchard using a WCF service.
It depends on what kind of data you need to access, but you will probably need to create a custom content part which dynamically loads data instead of using the underlying SQL database through NHibernate. You can do this by inheriting from the non-generic ContentPart class (the generic one uses a record stored using NHibernate) and using a ContentHandler to populate the data from your custom data source.
There is an experimental RavenDB-based data layer implementation in 'ravendb' Mercurial branch.
It was built a couple of months ago and I'm not sure about the compatibility with the current release, but you can give it a try. There were no big changes to DL since then so I assume it should work or need just a couple of tweaks.

Using NHibernate for DotNetNuke Modules?

I'm thinking of adopting a more Domain-Driven-Design approach to DotNetNuke module development and would like to consider using NHibernate as an OR/M layer.
Does anyone have experience using NHibernate with DotNetNuke? I've used SubSonic and EntitySpaces, but not NH.
UPDATE
Sorry, I should have been more clear. Is NHibernate capable of running in Medium Trust and able to run in the context of the DotNetNuke "objectqualifier" ? The DNN object qualifier is essentially a prefix that can be applied to all database table names. So on my DNN install I might have a table named "Products", but on someone else's the same table might be named "dnn_Products" where the "dnn" is the "objectqualifier". So essentially NHibernate would need to read the objectqualifier from the web.config at runtime and apply it.
NHibernate can be used with essentially any table name. When you define the table mapping in your mapping xml you need to simply define the table name as dnn_Products. As long as that is the actual name of the table then it will work. NHibernate is capable of running in Medium Trust, the trick is getting the NHibernate dll's into your DNN install. You can add them in an Assembly Component from what I understand but I have never had the need to validate that personally.
You can see this example.
The article is not for the same topic you are looking but it will give you good idea about it.

Tool to generate Fluent NHibernate mappings

I am trying to integrate NHibernate into an existing application with several hundred tables. Due to the fact that there apparently wasn't a strict adherence to conventions, I am unable to use Automap. As a result, I'm going to use Fluent to manually map over all of the associations.
Rather than doing it by hand, I'm hoping that there is a tool in existance that can either run through my solution or the database and stub out mappings.
Does anyone know of any project out there with this in mind?
Thanks!
I don't know of a tool that does it in Fluent, but there are plenty of options for doing it with the old hbm xml files. CodeSmith and MyGeneration are two that are recommended as a starting point for your classes and hbms.
LLBLGen Pro V3 will do exactly this, it can generate either tradition .hbm.xml or fluent mappings for your entire database.
Old question, maybe still relevant to some. If you are looking for an open source solution, try NHibernate Mapping Generator

Mapping files generation with nhibernate

i m new to nhibenate and i really find it painful to write the entire mapping files is there a tool or a vs addin that helps you do the mapping ?
thx for your time :)
If you have an existing database that you want to map you can use the open source tool MyGeneration to create both mapping files and the domain objects from the database. In this screencast you can see how this can be done.
You can also use CodeSmith, however this is a commercial tool. This screencast shows the use of this tool with NHibernate.
If you write the XML yourself, make sure that you have intellisense in VS. This blog describes how this is done.
If it is just the XML you don't like, check out http://wiki.fluentnhibernate.org where you do the mapping with C# code. Check out this blog post (mine) for an example.
You can also do the mapping with Attributes, but there seems to be not to many examples of this.
You can also check out Caste ActiveRecord, which "is built on top of NHibernate, but its attribute-based mapping free the developer of writing XML for database-to-object mapping, which is needed when using NHibernate directly". Here are some tutorials on this.

NHibernate : Do i have to create classes & objects by hand?

I am creating DAL with NHibernate. do i need to create classes & mapping files by hand ?
Like in Linq to Sql & Entity Framework they are created automatically by vsts?
Is there any such tool for NHibernate ?
There is a new commerial tool for nhibernate that does what you want called Visual NHibernate: http://www.slyce.com/
There is also a free open source one called Active Writer: http://altinoren.com/activewriter/
Most people prefer to write the mapping and classes by hand because the greater power and flexibility it gives. So I would personally not recommend to auto generate it unless perhaps it is a simple report app.
Fluent NHibernate, a separate open source project that builds on NHibernate, will Automap classes (with certain restrictions).
This is a link to the documentation page for Auto Mapping
(If this was helpful in any way, please vote for it. And when you get a few answers, mark the best one as Accepted)
Focusing on your domain is kind of the point of NHibernate. It gets coders out of writing SQL and into writing code, which is what we're supposed to be good at.