Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6636151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:08:58+00:00 2026-05-25T23:08:58+00:00

Hi I start learn Fluent NHibernate. I am using this tutorial http://www.d80.co.uk/post/2011/02/20/Linq-to-NHibernate-Tutorial.aspx . Here

  • 0

Hi I start learn Fluent NHibernate. I am using this tutorial http://www.d80.co.uk/post/2011/02/20/Linq-to-NHibernate-Tutorial.aspx.

Here is my sample code:

public class Account
{
    public virtual int Id { get; set; }
    public virtual string Nick { get; set; }
    public virtual string Password { get; set; }
}

public class AccountMap:ClassMap<Account>
{
    public AccountMap()
    {
        Id(x => x.Id);
        Map(x => x.Nick);
        Map(x => x.Password);
    }
}

public class  NHiberanteHelper
{
    private static ISessionFactory _sessionFactory;

    private static ISessionFactory SessionFactory
    {
        get
        {
            if (_sessionFactory == null)
                InitializeSessionFactory();

            return _sessionFactory;
        }
    }

    private  static void InitializeSessionFactory()
    {

        _sessionFactory = Fluently.Configure()

            //NHibernate bude pouzivat ovladace pre MS SQL 2008
            .Database(MsSqlConfiguration.MsSql2008
                          .ConnectionString(
                               @"Server=JAN-MSI\SQLEXPRESS;Database=SimpleNHibernate;Trusted_Connection=True;").ShowSql()
                              )

            //urci NHibernatu kde ma hladat mapovacie subory
            .Mappings(m=>m.FluentMappings.AddFromAssemblyOf<Account>())

            //ak tabs nie su v DB vytvori
            .ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true))

            //vytvori jeden session pre cely life-time apps
            .BuildSessionFactory();
    }

    public static ISession OpenSession()
    {
        return SessionFactory.OpenSession();
    }
}

class Program
{
    static void Main(string[] args)
    {
        using (var session = NHiberanteHelper.OpenSession())
        {
            using (var trans = session.BeginTransaction())
            {
                var account = new Account
                                  {
                                      Nick = "dfdwf",
                                      Password = "xxx"
                                  };
                session.Save(account);
                trans.Commit();

            }
        }
        Console.ReadKey();
    }
}

Problem is that this Fluent configuration always drop table in database.

I need only check if table doesnt exist so create table not always when code run drop table.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:08:59+00:00Added an answer on May 25, 2026 at 11:08 pm

    Your call to new SchemaExport(cfg).Create(true, true) is exporting the configuration to the database. This will drop and re-create it (it’s not clever enough to work out the differences and just execute them.

    You could use SchemaUpdate, which will update the schema instead. Here’s a blog post about it: http://geekswithblogs.net/dotnetnomad/archive/2010/02/22/138094.aspx

    I would always prefer to update tables myself or use something like Redgate’s SQLCompare to update a schema whilst preserving data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I start learn EF Fluent API. I have 2 simple POCO classes. public class
I want to start to learn about using webservices, and the best way to
I've been using NetBeans with xampp in windows Desktop. Now I start to learn
Just start to learn Java, and always see some tutorials mentioning, using the javaDoCs
I'm trying to learn x86. I thought this would be quite easy to start
I start to learn asm using fasm, unfortunately after compile code below I get
I just start to learn web programming using IIS 7.5 in windows 2008 R2,
I start to learn Prolog and first learnt about the successor notation. And this
I'm a little bit confused. I want to start learn Flex3 with Eclipse and
I'm learned php as functional and procedure language. Right now try to start learn

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.