Try this before building the session factory:
var mapper = new ModelMapper();
mapper.AddMapping<ModelMap>();
var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
Configuration.AddDeserializedMapping(mappings, null);
RP
On Thursday, June 26, 2014 10:57:53 PM UTC+1, Michael Murphy wrote:
>
> Hello all,
>
> I've been using Castle ActiveRecord and am interested in starting a new
> project using just NHibernate. I'd like to use the latest stable release
> which appears to be v3.3.3.4001. I'd like to use the Mapping ByCode
> feature since that is similar to the Castle ActiveRecord that I have been
> working with and seems to offer me the quickest approach to working. I've
> created a simple class
>
> public class Model {
> public virtual long ID { get; set; }
>
> }
>
> public class ModelMap : ClassMapping<Model> {
> public ModelMap() {
> Id(x => x.ID, m => m.Generator(Generators.Identity));
> Lazy(false);
> }
> }
>
>
> i've created a simple MSTest Unit Test
> using SyLogis.Models;
> using Microsoft.VisualStudio.TestTools.UnitTesting;
> namespace TestProject1
> {
> [TestClass()]
> public class ModelTest {
>
> static InMemoryDatabaseTest imdb = null;
>
>
> [ClassInitialize()]
> public static void MyClassInitialize(TestContext testContext) {
> System.Reflection.Assembly assembly =
> typeof(NumberedEntityMap).Assembly;
> imdb = new InMemoryDatabaseTest(assembly);
> }
>
> [TestMethod()]
> public void ID_Test() {
> Model target = new Model(); // TODO: Initialize to an appropriate
> value
> long expected = 1; // TODO: Initialize to an appropriate value
> long actual;
> target.ID = expected;
> actual = target.ID;
> imdb.session.Save(target);
> target = null;
> target = imdb.session.Get<Model>(expected);
> Assert.AreEqual<long>(expected, target.ID);
> }
> }
> }
>
> and here is the inmemory piece
> using System;
> using System.Collections.Generic;
> using System.Linq;
> using System.Text;
> using NHibernate;
> using NHibernate.Cfg;
> using NHibernate.Tool.hbm2ddl;
> using System.Reflection;
> using System.Data;
>
>
> namespace TestProject1 {
>
> public class InMemoryDatabaseTest : IDisposable {
>
> public static Configuration Configuration;
> public static ISessionFactory SessionFactory;
> public ISession session;
> public IDbConnection connection;
>
> public InMemoryDatabaseTest(Assembly assemblyContainingMapping) {
> try {
> if (Configuration == null) {
> Configuration = new Configuration()
> .SetProperty(NHibernate.Cfg.Environment.ConnectionProvider,
> "NHibernate.Connection.DriverConnectionProvider")
> .SetProperty(NHibernate.Cfg.Environment.ConnectionDriver,
> typeof(SQLite20Driver).AssemblyQualifiedName)
> .SetProperty(NHibernate.Cfg.Environment.ConnectionString,
> "Data Source=:memory:;Version=3;New=True;")
> .SetProperty(NHibernate.Cfg.Environment.ShowSql, "false")
> .SetProperty(NHibernate.Cfg.Environment.Dialect,
> typeof(SQLiteDialect).AssemblyQualifiedName)
> .SetProperty(NHibernate.Cfg.Environment.ReleaseConnections,
> "on_close")
> .SetProperty(NHibernate.Cfg.Environment.MaxFetchDepth, "1")
> .AddAssembly(assemblyContainingMapping);
>
> SessionFactory = Configuration.BuildSessionFactory();
> }
>
> session = SessionFactory.OpenSession();
> connection = session.Connection;
> new SchemaExport(Configuration)
> .SetOutputFile(".\\sqlite.sql")
> .Execute(true, true, false, connection, Console.Out);
>
> } catch (Exception ex) {
> throw;
> }
> }
>
>
> public void Dispose() {
> session.Dispose();
> }
> }
> }
>
>
> when i run the test it goes fine until it gets to the Save step at which
> point it throws an exception and the test details says there's no
> persister. I'm not certain what I'm doing wrong. I don't have any hbm.xml
> files to add as Embedded Resources (but I thought that was the point of
> Mapping ByCode). I would appreciate any suggestions.
>
> Also all the NHibernate Getting Started samples I can find are for v3.1.0
> of NHibernate or even more often v2.1.x or similar. Are there any Getting
> Started samples using v3.3.3? If anyone has a working Visual Studio
> Solution using NHibernate v3.3.3 and could send it to me or post it
> somewhere, that would be much appreciated. Thanks in advance. Have a
> great day!
>
>
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.