Im trying to insert object into SQLite InMembory database as follow:
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 Im getting ERROR: "SQLite error\r\nno such table: Person"
Just for clarification: Im using InMemory option.
I'm also using FluentNhibernate with 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 im doing wrong? Thanks in advance.
I know it is an old post,
I was faced the same problem, actually i wrote schema export exactly. But the exception is till appear.
The problem is you need to use you opened session to execute the schema export. So you need to modify your configuration.
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();
once you make session by OpenSession()
use that to feed your 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);
I hope it will help some body else who face the same problem.
Note
I Used NHibernate 2.1.2, Fluent NHibernate 1.1 and .Net 3.5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With