Before asking here I read all post relative to the subject but I can't find any solution.
I removed all my domain complexity and I'm down to the following simple issue:
I have 2 class (in a domain file Domain.cs) :
public abstract class BaseClass
{
public virtual int ID { get; set; }
public virtual string Name { get; set; }
}
public class ASubClass : BaseClass
{
public ASubClass() {}
public virtual string prop { get; set; }
}
My Mapping is (In another file Mapping.cs):
public class BaseClassMap : ClassMap<BaseClass>
{
public BaseClassMap ()
{
Id(x => x.ID).GeneratedBy.HiLo("1000");
Map(x => x.Name);
DiscriminateSubClassesOnColumn("Type");
}
}
public class ASubClassMap : SubclassMap<ASubClass>
{
public ASubClassMap ()
{
Map(x => x.prop);
DiscriminatorValue(1);
}
}
First I let NHibernate create the DB for me :
var cfg = new NHibernate.Cfg.Configuration();
Fluently.Configure(cfg)
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(connectionstring)
.ShowSql())
.Mappings(m => m
.FluentMappings.AddFromAssemblyOf<BaseClass>()).BuildConfiguration();
new SchemaExport(cfg).Execute(false,true,false);
This works great, then my unit test is the following : I build a session Factory within a Repository and use the Session/Transaction to try to save an empty SubClass:
var contract = new ASubClass();
IRepository<ASubClass> repository = new Repository<ASubClass>();
repository.Add(contract); >>> BUG HERE
This in fact bug on the line(inside the repo) : session.Save(contract);
I tried to copy/paste my Mapping.cs into Domain.cs or change the attribute of
.FluentMappings.AddFromAssemblyOf<BaseClass>
to .FluentMappings.AddFromAssemblyOf<BaseClassMap>
I also tried to change the hierarchy of subclass by removing the Discriminator and the DiscriminateSubClassesOnColumn keyword.
Didnt work so far.
Thanks.