我需要一些帮助确定如何开展工作。 I m 建造一台机器,管理记录收集,我有以下地图。
<class name="Soulful.Core.Domain.Model.Record,Soulful.Core" table="Record">
<id name="Id" type="Int32" unsaved-value="0">
<generator class="native" />
</id>
<many-to-one name="Artist" class="Soulful.Core.Domain.Model.Artist,Soulful.Core" foreign-key="FK_Artist_Id" cascade="all">
<column name="ArtistId" not-null="true" />
</many-to-one>
.... more properties
</class>
<class name="Soulful.Core.Domain.Model.Artist,Soulful.Core" table="Artist">
<id name="Id" type="Int32" unsaved-value="0">
<generator class="native" />
</id>
<property name="Name" type="string" not-null="true" />
</class>
我希望许多记录能够向一位艺术家绘制地图,而这项工作只是罚款。 但是,在我试图删除记录时,我遇到了麻烦。 我想做的是:
如果与艺术家没有其他记录,则删除记录和艺术家。 如果存在与艺术家有关的记录,则删除记录。
随着目前的绘图,我在我打电话时遇到以下错误。 删除(记录);
NHibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations)[Soulful.Core.Domain.Model.Artist#3]
这里,我删除的Method认为:
public virtual void Delete(T entity)
{
using (var session = GetSession())
using (var transaction = session.BeginTransaction())
{
try
{
session.Delete(entity);
transaction.Commit();
}
catch (HibernateException)
{
transaction.Rollback();
throw;
}
}
}
What would I need to do to have it working the way I want it to? Please feel free to state obvious.
Update I guess I m asking if I need to handle deletion of artists manually?