Entity Framework: Generating database from classes - orm

Is it possible to create the database from the classes with entity framework 4.0? I found many tutorials on how to do it the other way round. But since we have already implemented and tested all classes of the domain we'd like to avoid changing them to much.
If I used the wrong keywords in Google I'd appreciate you could post a link.
Cheers,
CA

Yes, it is possible. The approach is known as "model-first".
You define your entities with designer then call for "Generate database script" or something. Run this SQL against a database and it will create tables and relationships.

This is quite easy to do with Fluent NHibernate using Auto Mapping. You could also use Fluent Mapping if you want more control over how your entities are mapped, but this will require writing mapping classes. It shouldn't affect your existing classes though.

While looking up an other question on Stackoverflow I found an the solution for my problem:
Entity Framework 4 / POCO - Where to start?

Related

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

Nhibernate mapping generator

I was wondering if there is a tool to generate Nhibernate mapping and class automatically from the database, kinda what subsonic does? Thanks in advance.
NHibernate Mapping Generator
Project Description
A simple utility to generate
NHibernate mapping files and
corresponding domain classes from
existing DB tables.
Screenshot http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=nmg&DownloadId=57926
It's in beta, I've not tried this though :)
In case its still relevant - have a look at the Mindscape NHibernate Designer if you are interested in a Visual Studio integrated option.
Some more screenshots are here
Its probably the closest to what you would get with Subsonic, and it covers most of the commercial databases out there for the drag/drop and 2 way round tripping, so its pretty easy to cover off most modelling concerns.
Note: I am one of the founders of Mindscape, so have a clear bias towards the product :)
There a new 2.0 Beta 2 release available with lots of new features and support for fluent nhibernate, one-to-many and many-to-many mapping.
http://www.codeplex.com/Wikipage?ProjectName=nmg

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.

nHibernate - Generate classes from a database?

I know that you can generate a database from classes and their mappings using nHibernate, but I can't find any good links to do this the other way around. We have a database that has already been designed, and we are looking at using nHibernate. It would be nice to use a tool to generate the mappings and classes from the database, and then we could tweak/manipulate them to suit our tastes.
NHibernate Mapping Generator
You can use nhibernate with an existing database. It is a matter of writing the mapping files.
I also recommend using Fluent Nhibernate...I started using this after this community recommended it..
Look at subsonic as well if you do not like maintenance of mappings.