c# - Not able to delete the foreign key contraint in Nhibernate Mappings -
public class reviewmap : classmapbase<review> { public reviewmap() { table("reviews"); list(x => x.objectives, m => { m.table("objectives"); m.cascade(cascade.all.include(cascade.deleteorphans)); m.key(k => k.column("reviewid")); m.where("deletiondate null"); m.orderby("orderno"); m.index(x => x.column("orderno")); m.inverse(true); }, m => m.onetomany()); } public class objectivemap : classmapbase<objective> { public objectivemap() { table("objectives"); // use "soft deletes" allow capture results against deleted items where("deletiondate null"); sqldelete("update objectives set deletiondate = getutcdate(), orderno = 1 id=?"); manytoone(x => x.review, m => { m.column("reviewid"); m.notnullable(true); }); property(x => x.details, m => { m.notnullable(true); m.length(1000); m.column("details"); }); property("orderno", m => { m.notnullable(false); }); } }
when try delete reviews gives me error foreign key constraint in objective table. reviewid foreign key in objectives table.
can suggest problem ?
you prevent deletions in objectives table custom sql-delete require objectives have reference review row. how should work? require reviews never deleted.
a way can work if remove foreign key constraint on objectives.reviewid column, wouldn't recommend that. since id of deleted review row won't history purposes, better way make objectives.reviewid column nullable , null out in custom sql-delete.
Comments
Post a Comment