我试图将对象插入SQLite InMembory数据库,如下所示:
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()) .BuildSessionFactory(); }
但我得到错误:"SQLite error\r\nno such table: Person"
只是为了澄清:我使用InMemory选项.
我也在使用FluentNhibernate和映射:
public class PersonMap : ClassMap{ 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); } }
我做错了什么?提前致谢.
我知道这是一个老帖子,
我遇到了同样的问题,实际上我完全写了架构导出.但例外是直到出现.
问题是您需要使用打开的会话来执行架构导出.所以你需要修改你的配置.
ISessionFactory session = Fluently.Configure() .Database(SQLiteConfiguration.Standard.InMemory()) .Mappings(m => m.FluentMappings.AddFromAssemblyOf()) .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