Hi durtal,
I guess the problem with the assigned id's is that NHibernate cannot find out by itself whether an entity is transient or persistent.
You can solve this by helping NHibernate a bit.
Therefor you can create an interceptor:
Code:
using NHibernate;
using ObjectFramework.Repository;
namespace ObjectFramework.NHImpl.Interceptor
{
public class IsUnsavedInterceptor:EmptyInterceptor
{
public override bool? IsUnsaved(object entity)
{
if (entity is IPersistence)
{
return ((IPersistence)entity).IsNew();
}
else
{
return false;
}
}
}
}
... an interface that your entity in question should implement:
Code:
namespace ObjectFramework.Repository
{
public interface IPersistence
{
bool IsNew();
void SetNew();
}
}
Code:
using ObjectFramework.Repository;
namespace ObjectFramework.Binding
{
public class EntityBaseWithAssignedId:EntityBase,IPersistence
{
private bool isNew=false;
bool IPersistence.IsNew()
{
return isNew;
}
void IPersistence.SetNew()
{
isNew=true;
}
}
}
... and finally call the following line for each new entity you create:
Code:
((IPersistence) newEntity).SetNew();
Maybe there are easier ways to get the job done, but at least this works for me.