Usually this problem occurs because the session used to export the schema is
different to the session used to then query/execute against the db. The
problem with the sessions being different is that they don't share the same
underlying db connection, and you lose the changes made in the schema step
by the time the query step occurs.

I suggest you do this instead:
- instantiate a NHibernate.Cfg.Configuration instance, and pass that in to
the Fluently.Configure() method.
- Remove the step where you build the schema in the expose configuration.
- After you open the session, do this:
                using (var tx = session.BeginTransaction())
                {
                    SchemaExport export = new SchemaExport(cfg);
                    export.Execute(true, true, false, false,
session.Connection, null);
                    tx.Commit();
                }
That code block is a paste from my project, you might have to adjust it
depending on your export settings. The key thing is that it passes in
session.Connection to ensure that the schema export occurs on the same
connection as the session.

Then with the same open session you can do your:

IList<User> list = session.CreateCriteria(typeof(User)).List<User>();

Let me know how it goes.

Paul Batum

On Sun, Apr 26, 2009 at 7:32 AM, Marcos Matos <marcos...@gmail.com> wrote:

> Thanks for the quick reply, i forgot to add the expose configuration part
> on my example .I've add the expose configurations lines following the
> guidelines on the wiki part of schemaexport, but I'm still getting the same
> exception.
>
> ISessionFactory factory = Fluently.Configure()
>
> .Database(SQLiteConfiguration.Standard.InMemory)
>                                                    .Mappings(m =>
> m.FluentMappings
>
> .AddFromAssemblyOf<User>())
>
> .ExposeConfiguration(BuildSchema)
>                                                    .BuildSessionFactory();
>
> private static void BuildSchema(Configuration cfg)
>         {
>            new SchemaExport(cfg)
>             .Create(false, true);
> }
>
>
> I'm doing something else wrong?
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to