I have a Project class that has a bag of Release classes, representing a one-to-many relationship. When attempting to perform a Delete operation on the Project class I get the following error:
SQL insert, update or delete failed (expected affected row count: 1, actual affected row count: 5). Possible causes: the row was modified or deleted by another user, or a trigger is reporting misleading row count.
I have cascade deletes enabled in SQL Server for the tables
Here is the code I am attempting to use:
Project existingProject;
try
{
using (Repository r = new Repository())
{
r.Open();
r.BeginTransaction();
existingProject = (Project)r.Get(typeof(Project), 1);
// 1 is a valid Project ID
r.CommitTransaction();
}
using (Repository r = new Repository())
{
r.Open();
r.BeginTransaction();
r.Delete(existingProject);
r.CommitTransaction();
}
}
catch
{
throw;
}
And my mappings:
<!-- generated using NHibernate.hbm.cst, see
http://www.intesoft.net/nhibernate for notes and latest version -->
<class name="Scorecard.Entities.Project, Scorecard.Entities" table="tblProject">
<id name="ID" type="Int32" unsaved-value="0">
<column name="ProjectID" sql-type="int" not-null="true" unique="true" index="PK_tblProject"/>
<generator class="native" />
</id>
<property name="Name" type="String">
<column name="Name" length="50" sql-type="varchar" not-null="true"/>
</property>
<property name="SummaryID" type="Int32">
<column name="SummaryID" sql-type="int" not-null="true"/>
</property>
<bag name="Releases" inverse="true" lazy="false" cascade="all">
<key column="ProjectID"/>
<one-to-many class="Cintas.Scorecard.Entities.Release, Cintas.Scorecard.Entities"/>
</bag>
<bag name="ProjectMetrics" inverse="true" lazy="false" cascade="all">
<key column="ProjectID"/>
<one-to-many class="Cintas.Scorecard.Entities.ProjectMetric, Cintas.Scorecard.Entities"/>
</bag>
</class>
</hibernate-mapping>
Any help would be much appreciated