流畅的nhibernate,删除不可为空的属性并替换它
我有一个具有不可为空属性的对象。
class Notebook {
Blueprint Blueprint { get; set; }
}
映射
// ...
NotebookMap() {
// ...
References(x => x.Blueprint)
.Not.Nullable()
.Cascade.All();
}
好的,太棒了。精彩的。
如果我想更改附加到笔记本的蓝图
并删除旧蓝图,会发生什么情况?这不起作用..
notebook.Blueprint = // new blueprint code.;
效果很好...但是旧的蓝图不会被删除,它只是愉快地挂在代码中并浪费空间。
如果我尝试这个..
session.Delete(notebook.Blueprint);
我会得到一个错误,因为现在该字段为空(并且它必须是不可为空的)。
有什么办法可以解决这个问题吗?
I have an object with a non-nullable property.
class Notebook {
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的事情怎么样?
当然,该蓝图可能被其他笔记本引用,所以删除仍然可能失败。
How about something like this?
Of course, the blueprint may be referenced by another notebook, so the delete may still fail.