Fluent NHibernate:哪个更好...从视图中选择或执行联接以从相关表中检索 MIN 和 MAX 值?
免责声明:我对 NHibernate/Fluent NHibernate 还很陌生。
我有一个事件表:
ID UniqueIdentifier,
Name varchar(100),
Details varchar(MAX)
....
我还有一个显示事件位置的查找表:
ID UniqueIdentifier,
StartDate datetime,
EndDate datetime,
City varchar(100)
....
我想要做的是在返回事件列表时从位置表中返回 MIN(StartDate) 和 MAX(EndDate) 值。
现在,按照传统,我会在 SQL 中为事件表构造一个视图,以返回这些聚合值。根据我的理解,如果我要在使用 NHibernate 时执行此操作,我需要创建两个 Fluent 映射,一个用于查看(引用我的 SQL 视图),另一个用于插入/编辑,引用我的表。
我说得对吗?
我想到的另一个选择是,在 Fluent 映射中,我可以以某种方式针对相关位置表执行聚合 MIN 和 MAX 函数。
哪种方法是首选方法?我将如何完成任务?
谢谢-乔尔
Disclaimer: I'm pretty new to NHibernate/Fluent NHibernate.
I have a table of events:
ID UniqueIdentifier,
Name varchar(100),
Details varchar(MAX)
....
I also have a lookup table that shows locations of the events:
ID UniqueIdentifier,
StartDate datetime,
EndDate datetime,
City varchar(100)
....
What I want to do is to return the MIN(StartDate) and MAX(EndDate) values from my locations table when returning a list of my events.
Now, traditionally, I would construct a View in SQL for my event table that returned these aggregate values. From my understanding, if I were to do this when using NHibernate, I would need to create two Fluent maps, one for viewing (that references my SQL View), and one for inserting/editing, that references my table.
Am I correct?
The other option I was thinking is that within my Fluent mapping, I could somehow perform the aggregate MIN and MAX functions against the related locations table.
Which is the preferred method, and how would I go about accomplishing the task?
Thanks - Joel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果最小值和最大值用于特定事件,您可以将其映射为:
这些属性是只读的(永远不会写回) (作为一个往返发出 3 个查询)
注意:如果应该全局使用 future,则
if the min and max is for specific events you can map it like:
Note: these Properties are readonly (never written back)
if it should be global use futures (3 queries issued as one roundtrip)