I have an object with a non-nullable property.
class Noteboo开发者_JS百科k {
Blueprint Blueprint { get; set; }
}
Mapping
// ...
NotebookMap() {
// ...
References(x => x.Blueprint)
.Not.Nullable()
.Cascade.All();
}
Okay, great. Wonderful.
What happens if I want to change the Blueprint
attached to a notebook, and delete the old blueprint? This doesn't work..
notebook.Blueprint = // new blueprint code.;
That works fine... but then the old blueprint isn't deleted, it just hangs around in code happily and wastes space.
If I try this ..
session.Delete(notebook.Blueprint);
I get an error, because now the field is null (and it has to be non-nullable).
Is there any way around this problem?
How about something like this?
var oldBlueprint = notebook.Blueprint;
notebook.Blueprint = // new blueprint code;
session.Flush(); // might or might not be needed
session.Delete(oldBlueprint);
Of course, the blueprint may be referenced by another notebook, so the delete may still fail.
精彩评论