The code fails at
session.Save(employee);
with AssertionFailure "null identifier". What am I doing wrong?
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Mapping;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
namespace FNHTest
{
public class Employee
{
public virtual int Id
{
get;
private set;
}
public virtual string Name
{
get;
set;
}
public virtual string Surname
{
get;
set;
}
}
public class EmployeeMap : ClassMap
{
public EmployeeMap()
{
Id(e => e.Id);
Map(e => e.Name);
Map(e => e.Surname);
}
}
public class DB
{
private static ISessionFactory mySessionFactory = null;
private static ISessionFactory SessionFactory
{
get
{
if (mySessionFactory == null)
{
mySessionFactory = Fluently.Configure()
.Database(MsSqlCeConfiguration.Standard
.ConnectionString("Data Source=MyDB.sdf"))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf())
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}
return mySessionFactory;
}
}
private static void BuildSchema(Configuration configuration)
{
SchemaExport schemaExport = new SchemaExport(configuration);
schemaExport.Execute(false, true, false);
}
public static ISession OpenSession()
{
return SessionFactory.OpenSession();
}
}
public class Program
{
public static void Main(string[] args)
{
var employee = new Employee
{
Name = "John",
Surname = "Smith"
};
using (ISession session = DB.OpenSession())
{
session.Save(employee);
}
}
}
}