2

Is there a generator to create mapping files for Fluent NHibernate based on a database schema which already exists?

I need to write a data layer for a application, which uses an database of another application. There are more than 300 tables so there is no way to create all these mapping files manually.

Fluent NHibernate is NOT allowed to change any table definition.

A solution for dynamic objects at runtime would be perfect, but it's also ok to create the mapping at design time.

2
  • You may already know this and possibly have more updated info, but just to make sure you've not missed it; if you're going for a newer version of NHibernate, fluentnhibernate may not be the way to go; lostechies.com/jamesgregory/2011/04/13/me-on-nhibernate-3-2 Commented Jan 27, 2012 at 8:46
  • Based on that blog personally I would still go with FNH. Commented Jan 27, 2012 at 8:54

2 Answers 2

1

If your database follows naming conventions, you could try looking at the automapping feature of FNH.

If you see that 80% of cases are covered be automapping, then create specific mappings for specific cases.

Have a look at this : http://wiki.fluentnhibernate.org/Auto_mapping

Sign up to request clarification or add additional context in comments.

Comments

0

If your database is using standard conventions, use AutoMapping and create conventions for it that match your database. Any tables that vary from those conventions, use convention overrides.

Note that if you are not going to recreate your database from your mappings at any time, you can keep all your existing indexes and nullability values and probably ignore them in the mapping, although be prepared to handle Sql errors if, for example, you have a non-nullable database column that is nullable to NHibernate. If you want to be really tight, you can define all your indexes and nullability settings in overrides as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.