I have a table Communication which has a reference to PersonCompany. In the mapping for PersonCompany i have defined a Cascade-Delete for this reference:
this.HasMany(x => x.Communications)
.AsSet()
.KeyColumn("PersonCompanyId")
.Fetch.Select()
.Inverse()
.Cascade.Delete();
But when I now execute the fallowing HQL-Query:
var sql = "delete from PersonCompany where Person.Id in (:idList) or Company.Id in (:idList)";
with
var query = NHibernateHelper.CurrentSession.CreateQuery(sql);
query.SetParameterList("idList", contactIdList);
query.SetTimeout(0);
query.ExecuteUpdate();
I always get this SqlException:
The DELETE statement conflicted with the REFERENCE constraint "FK_PersonCompany_Communication". The conflict occurred in database "proconact", table "dbo.Communication", column 'PersonCompanyId'. The statement has been terminated.
I think, NHibernate should now delete cascade the referenced records in Communication - should'nt it?
I hope someone can help me, what I am doing wrong.