Anyone who tried something similar? Having SchemaUpdate (or even SchemaExport) to create database relationships with On Delete option equal to Set Null ?
Just wanna make sure it's an issue with Schema Update or it should be done in certain way that I didn't figure out. Thank you. Regards, -- Mohamed Meligy Senior Developer, Team Lead Backup (.Net Technologies - TDG - Applications) Injazat Data Systems P.O. Box: 8230 Abu Dhabi, UAE. Phone: +971 2 6992700 Direct: +971 2 4045385 Mobile: +971 50 2623624, +971 55 2017 621 E-mail: [email protected] Weblog: http://weblogs.asp.net/meligy On Sun, Jan 10, 2010 at 2:03 AM, Mohamed Meligy <[email protected]>wrote: > I'm using NHibernate in a project in a code-first way that s encouraged > here. To make this work best, I use "SchemaUpdate" class to create my DB > schema so that I hardly have to touch the database. > > Recently I went through a situation that can be simplified in Northwind > terms as: > " Let's say we have a ZERO to many relation between Category and Product. A > Product can have a Category or not (non-categorized)." > > Speaking about DB, if we delete a category from a database, we want the > Product Category ID to be set to null. The DB relation would have the action > on delete as Set Null. > > Now I'm not modifying the database myself, and multiple developers have > their own instances of the DB. I do not want to have to update the DB schema > manually for this specific relation setting only. > > The mapping on-delete option allows none or cascade delete. I do not know > how to have the Set Null option. I already have the category ID nullable but > it's not setting it to null. > > How do I get that to work? I need the Many FK to be set null when I delete > the zero/one side of the relationship. Can it be achieved in NHibernate? > > I think the problem is not with mapping or deleting operation. Mot probably > the problem (I guess) is with "SchemaUpdate". If the on-delete action is > none/no-action, and the FK is nullable and has no Default Value, > SchemaUpdate should set the on-delete setting of the relation to SetNull. > This doesn't happen! > > Am I missing something? Is there a problem with that? > > > By the way, right now I work around this by making an HQL update statement > that updates the children "Many" setting their FK to NULL first thing in the > transaction that executes the category delete Session method-call. Not a > very expensive solution, but I'm curious about whether there is a > more-native / right way of doing this. > > Thanks. > Regards, > > -- > Mohamed Meligy > Senior Developer, Team Lead Backup (.Net Technologies - TDG - Applications) > Injazat Data Systems > P.O. Box: 8230 Abu Dhabi, UAE. > > Phone: +971 2 6992700 > Direct: +971 2 4045385 > Mobile: +971 50 2623624, +971 55 2017 621 > > E-mail: [email protected] > Weblog: http://weblogs.asp.net/meligy >--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
