如何使用公式和列规范映射 NHibernate 实体属性
我试图以这样的方式映射实体属性,将其值写入数据库列,但使用公式检索其值。
为了关注实际问题,我简化了示例。实际上,该公式有点复杂,并且使用 NHibernate 过滤器。
<many-to-one cascade="all" class="Thing" lazy="false" name="MyThing"
formula="(SELECT Things.Value FROM Things WHERE Things.Id = MyThingId)">
<column name="MyThingId" />
</many-to-one>
但是,除非我删除
行,否则该公式将被忽略。
我将如何修复此映射以便 NHibernate 使用该公式?
I'm trying to map an entity property in such way that it writes its value to a database column but retrieves its value using a formula.
To focus on the actual issue, I have simplified the example. In reality the formula is a bit more complex and is using an NHibernate filter.
<many-to-one cascade="all" class="Thing" lazy="false" name="MyThing"
formula="(SELECT Things.Value FROM Things WHERE Things.Id = MyThingId)">
<column name="MyThingId" />
</many-to-one>
The formula is ignored however, unless I remove the <column name="MyThingId" />
line.
How would I fix this mapping in order to have NHibernate use the formula?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为不可能完全做到你正在尝试的事情。
为什么不把财产一分为二呢?一个是公式的只读属性,另一个是直接列映射的读/写...
如果您仍然需要单个访问点,您可以映射第三个被忽略的属性,该属性实现它的
get
和使用前两个属性设置
访问器。I don't think it's possible to do exactly what you are trying.
Why not split the property in two? One readonly for the formula and the other read/write with a direct column mapping...
If you still want a single access point, you can map a third ignored propery that implements it's
get
andset
accessors with the two first properties.