在我把我的电脑踢到下周之前......
我已经检查了有关此的所有其他问题,但没有一个有解决方案。我已经删除了这段代码,但它仍然无法正常工作。
保存对象时出现此错误:NHibernate.AssertionFailure: null identifier
这是我的映射文件:
public class OrderMap : BaseMap<Order>
{
public SalesOrderMap()
{
Id(x => x.Id).Column("OrderId");
}
}
这是实体:
public class Order
{
public virtual int Id { get; protected set; }
}
这是我的测试代码:
Order order = new Order();
ISession session = SessionFactory.GetCurrentSession();
session.SaveOrUpdate(order); <----EXCEPTION ON THIS LINE
session.Flush();
然后砰的一声……它打破了
[AssertionFailure: null identifier]
NHibernate.Engine.EntityKey..ctor(Object identifier, String rootEntityName, String entityName, IType identifierType, Boolean batchLoadable, ISessionFactoryImplementor factory, EntityMode entityMode) +135
NHibernate.Engine.EntityKey..ctor(Object id, IEntityPersister persister, EntityMode entityMode) +70
NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) +545
NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) +322
NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) +130
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) +27
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event) +63
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event) +89
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event) +188
NHibernate.Impl.SessionImpl.FireSaveOrUpdate(SaveOrUpdateEvent event) +259
NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj) +256
如果有人感兴趣,这就是会话工厂的构建方式:
ControllerSource.SessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(DataConfig.ConnectionString))
.Mappings(x => x.FluentMappings.Add(typeof (OrderMap)))
.ExposeConfiguration(c =>{
c.SetProperty("generate_statistics", "false");
c.SetProperty("current_session_context_class", contextClass);
c.SetProperty("cache.use_second_level_cache", "false");
c.SetProperty("cache.use_query_cache", "false");
c.SetProperty("connection.release_mode", "on_close");
})
.BuildSessionFactory();