Fluent NHibernate 将日期和时间字段合并为 DateTime 对象
我有一个数据库表(我无法更改),它将日期和时间存储在单独的字段中,但我的类只有一个 DateTime 属性(已打开)。
DateOpened 2011-05-10 00:00:00.000
TimeOpened 1899-12-30 09:53:00.000
在 SQL 中我可以做
SELECT DateOpened + TimeOpened AS 'Opened'
How can I map this in Fluent NHibernate?我正在使用流畅的映射。
我已经尝试过
Map(x => x.Opened).Columns.Add(new string[] { "DateOpened", "TimeOpened" });
,但出现以下错误
property mapping has wrong number of columns: CBS.Tigerpaw.Data.ServiceOrder.Opened type: DateTime
I have a database table (which I cannot change) which stores the date and time in separate fields but my class only has one DateTime property (Opened).
DateOpened 2011-05-10 00:00:00.000
TimeOpened 1899-12-30 09:53:00.000
In SQL I could just do
SELECT DateOpened + TimeOpened AS 'Opened'
How can I map this in Fluent NHibernate? I'm using Fluent Mapping.
I have tried
Map(x => x.Opened).Columns.Add(new string[] { "DateOpened", "TimeOpened" });
but I get the following error
property mapping has wrong number of columns: CBS.Tigerpaw.Data.ServiceOrder.Opened type: DateTime
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果 IUsertype 是一个选项
if IUsertype is an option
您可以使用
.Map(...).Formula(...)
& 定义DateOpened + TimeOpened
您的班级中具有私有设置器的附加属性。you can define that
DateOpened + TimeOpened
by using the.Map(...).Formula(...)
& additional property in your class which has a private setter.您可能会考虑独立映射两个单独的列,然后让您的类提供一个附加的(且未映射的)“Opened”属性来集成它们的值。遗憾的是,这两个映射属性仍然作为公共属性可见,因为 Fluent NHibernate 需要这样做,以便映射类中的 lambda 表达式可以获取它们。
You might consider mapping the two separate columns independently and then having your class offer an additional (and un-mapped) "Opened" property that integrates their values. Regrettably, the two mapped properties would still be visible as public properties, since Fluent NHibernate requires this so that the lambda expressions in the mapping class can get at them.