Question

I have a question about how to render the sql schema with fluent nhibernate. I have searched alot and used a couple of things but i dont know how to render it. I´m only building the ground of my website, the core. And now i want to create the database from my mappings. How do i do that? Is it with testrunning or what?

If i build the solution i don´t get any sql file i have also tried export it to hbm files to use schema tool export but dont get it to work.

have tried Fluent NHibernate (1.2.0.712) export mappings to HBM not working / not respecting conventions

and https://stackoverflow.com/questions/5244257/build-schema-with-fluent-nhibernate

and alot other links.

What do i have to do to get the sql file? every site give almost the same code but they don´t tell how to render it. How to execute the process to retrieve the file..

can anyone tell me? i can build it by my self but i want to try this function! best regards

Was it helpful?

Solution

You can create the database using the SchemaExport.Create method:

            // this NHibernate tool takes a configuration (with mapping info)
            // and exports a database schema from it
            new SchemaExport(config)
                .Create(true, true);

If you want to see the generated SQL, you can use the ShowSql method, but this is not required to create the database.

            _sessionFactory = Fluently.Configure()
                .Database(SQLiteConfiguration.Standard
                              .UsingFile(SqliteDatabaseFullPath())
                              // Display generated SQL in Output window
                              .ShowSql()
                         )
                 ...

It's been my experience with NHibernate that it's almost always best to start with a working example, so I suggest you get the FirstAutomappedProject sample project that is part of the FNH source. This will give you all the pieces you need.

Probably easiest to download the zip file (button on the upper left) which includes all the FNH source code, and look in the "src" folder for the examples.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top