Fluent NHibernate:如何将整个类映射为只读?
我有一些类从非常微妙的表中读取,这就是为什么我希望 NHibernate 将它们用作“只读”。在每个字段映射上建立 .ReadOnly() 确实很草率,我不确定我是否相信它。如何将类设置为完全只读,就像使用传统 XML 映射可以轻松做到的那样?
编辑:答案确实有效。如果我尝试保存 ReadOnly() 对象,我预计它会抛出异常,但它只是默默地这样做。
谢谢。
I have a few classes that read from very delicate tables, which is why I want them to be used by NHibernate as "ReadOnly". Establishing .ReadOnly() on each field map is really sloppy, and I'm not sure I trust it. How do I setup a class to be entirely readonly, as I can easily do with traditional XML mappings?
Edit: The answer does work. I expected it to throw an exception if I tried to save over a ReadOnly() object, but it just silently does so.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Fluent NHibernate,一切就这么简单:
With Fluent NHibernate, it's as simple as:
ReadOnly() 属性实际上并不像您期望的那样工作。
使用此属性可确保您检索的对象是只读的,因此您无法更新它们。但是,它不会阻止创建新记录,甚至删除数据库中的现有记录!
The ReadOnly() property actually does NOT work like you would expect.
Using this property makes sure that the objects that you retrieve are read-only, so you cannot UPDATE them. However, it does NOT prevent the creation of new records or even the deletion of existing records in the database!