The FluentNHibernate concept is awesome!  However, right now it looks
like an untouchable treasure.

I downloaded and ran the Your_first_project project, which worked
fine.

I now branching out on my own, and finally have a project that
compiled.  But, when running it, it first gave me a dialog box asking
for some kind of information, which evidently I typed wrong.  I don't
seem to have a second chance at whatever that dialog presented.

Now, the following error shows up when it gets to session.SaveOrUpdate
(see code below)

NHibernate.MappingException was unhandled
  Message="No persister for: ORTest.TestClass"
  Source="NHibernate"
  StackTrace:
       at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String
entityName)
       at NHibernate.Impl.SessionImpl.GetEntityPersister(String
entityName, Object obj)
       at NHibernate.Engine.ForeignKeys.IsTransient(String entityName,
Object entity, Nullable`1 assumed, ISessionImplementor session)
       at
NHibernate.Event.Default.AbstractSaveEventListener.GetEntityState(Object
entity, String entityName, EntityEntry entry, ISessionImplementor
source)
       at
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent
event)
       at
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent
event)
       at
NHibernate.Impl.SessionImpl.FireSaveOrUpdate(SaveOrUpdateEvent event)
       at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
       at ORTest.Program.Main(String[] args) in C:\Visual Studio
Projects\ORTest\ORTest\Program.cs:line 21
       at System.AppDomain._nExecuteAssembly(Assembly assembly,
String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
       at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
       at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:


Here's the code I'm using:

    class Program {
        static void Main(string[] args) {
            var sessionFactory = CreateSessionFactory();
            using (var session = sessionFactory.OpenSession()) {
                var test = new TestClass();
                test.X = 15;
                session.SaveOrUpdate(test);
            }

        }

        private static ISessionFactory CreateSessionFactory() {
            return Fluently.Configure()
              .Database(MsSqlConfiguration.MsSql2005.ConnectionString("User
ID=.............."))
              .Mappings(m =>
m.FluentMappings.AddFromAssemblyOf<Program>())
              .ExposeConfiguration(BuildSchema)
              .BuildSessionFactory();
        }

        private static void BuildSchema(Configuration config) {
            // delete the existing db on each run
            if (File.Exists(DbFile))
                File.Delete(DbFile);

            // this NHibernate tool takes a configuration (with
mapping info in)
            // and exports a database schema from it
            new SchemaExport(config)
                .Create(false, true);
        }

    class TestClass {
        public virtual int ID { get; private set; }
        public virtual int X { get; set; }
    }

    class TestClassMap : FluentNHibernate.Mapping.ClassMap<TestClass>
{
        public TestClassMap() {
            Table("TestClass"); // my (wrong) guess at how to provide
a persister.
            Id(x => x.ID);
            Map(x => x.X);
        }
    }


My table:
CREATE TABLE [dbo].[TestClass](
        [ID] [int] IDENTITY PRIMARY KEY,
        [X] [int] NULL)



Can anyone help point me in the right direction?

I appreciate your help!

Kurt

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to