I have two tables:
- Receipt
- ReceiptJournal
Receipt
has 0...n ReceiptJournals
The mapping for this (in Receipt
) looks like:
this.HasMany(x => x.ReceiptJournals).AsSet().Fetch.Select().Inverse().Cascade.Delete();
The underlying database which I use is SQL Server CE 4.0.
Now, when I execute a delete-statement
const string sql = "delete from Receipt where IsFinished = 0 and IsParked = 0";
var query = NHibernateHelper.CurrentSession.CreateSQLQuery(sql);
query.ExecuteUpdate();
I get an exception:
Could not execute native bulk manipulation query:delete from Receipt where IsFinished = 0 and IsParked = 0[SQL: delete from Receipt where IsFinished = 0 and IsParked = 0]
System.Exception {NHibernate.Exceptions.GenericADOException}
[System.Data.SqlServerCe.SqlCeException] {"Der Primärschlüsselwert kann nicht gelöscht werden, da noch Verweise auf diesen Schlüssel vorhanden sind. [ Foreign key constraint name = FK_Receipt_ReceiptJournal ]"} System.Data.SqlServerCe.SqlCeException
Does NHibernate with SQL Server CE not support cascade delete or am I doing something wrong?