Sqlite "There is no such table" when saving an object

I am trying to insert an object into an SQLite InMembory database as follows:

private void button1_Click(object sender, EventArgs e)
    {
        var sessionFactory = CreateSessionFactory();
        using (var session = sessionFactory.OpenSession())
        {
            Person p = new Person { Age = 25, FirstName = "Dariusz", LastName = "Smith" };
            session.SaveOrUpdate(p);
            //transaction.Commit();
        }
    }

private static ISessionFactory CreateSessionFactory()
    {
        return Fluently.Configure()
        .Database(
        SQLiteConfiguration.Standard.InMemory().ShowSql())

        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Person>())
        .BuildSessionFactory();
    }

But I get ERROR: "SQLite error\r\nno such table: Person" For clarification only: I use the InMemory parameter.

I also use FluentNhibernate with a mapping:

public class PersonMap : ClassMap<Person>
{
    public PersonMap()
    {
        //Table("Person") doesn't resolve my problem
        Id(x => x.Id);
        Map(x => x.FirstName);
        Map(x => x.LastName);
        Map(x => x.Age);
    }
}

What am I doing wrong? Thanks in advance.

+5
source share
3 answers

. - NHibernate.Tool.hbm2ddl.SchemaExport. . - , .. CREATE TABLE Person .... , SchemaExport , , .

+4

, ,

, . .

, . .

ISessionFactory session = Fluently.Configure()
    .Database(SQLiteConfiguration.Standard.InMemory())
    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<MessagingDescriptorMap>())

    .ExposeConfiguration(c =>
    {
        config = c; //pass configuration to class scoped variable
    })
    .BuildSessionFactory();

, OpenSession(), SchemaExport.Execute

ISession session = GetSessionFactory().OpenSession();
//the key point is pass your session.Connection here
new SchemaExport(config).Execute(true, true, false, session.Connection, null);

, - , .

NHibernate 2.1.2, Fluent NHibernate 1.1 .Net 3.5

+19

As Darin Dimitrov said, you need to export the circuit. Fortunately, there is a good way to do this using Fluent NH :)

   return Fluently.Configure()
   .Database(SQLiteConfiguration.Standard.InMemory().ShowSql())
   .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Person>())
   .ExposeConfiguration(BuildSchema)
    .BuildSessionFactory();

... where BuildSchema is a method:

private void BuildSchema(Configuration cfg)
{
  new SchemaExport(cfg)
    .Create(false, true);
}

Source: http://wiki.fluentnhibernate.org/Schema_generation

+4
source

All Articles