Fluent NHibernate 中 Access.BackingField 的用例是什么?

发布于 2024-09-18 20:47:43 字数 254 浏览 1 评论 0原文

Access.BackingField() 的文档表明:

设置访问策略以使用自动属性的支持字段。

我知道自动属性是使用支持字段进行编译的,但如果该属性根据定义是普通的 getter/setter,那么直接访问支持字段与使用 setter(即使用 FNH 默认值)相比会获得什么优势。

我唯一能想到的是,如果后来有人向设置器添加逻辑,人们可能会希望映射被破坏。

我缺少什么?

The documentation for Access.BackingField() indicates that this:

Sets the access-strategy to use the backing-field of an auto-property.

I understand that auto-properties get compiled with backing fields, but if the property is by definition a vanilla getter/setter, what advantage is garnered by going to the backing field directly versus using the setter (i.e. using the FNH defaults).

The only thing I can think of is that one might want the mapping to break if someone later adds logic to the setter.

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悟红尘 2024-09-25 20:47:43

啊,我想我在此处找到了答案。

如果自动属性具有 private 访问器,请使用支持字段。

Ah, I think I found the answer here.

Use the backing field if the auto-property has a private accessor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文