流畅的 NHibernate 映射和公式/日期部分
我有一个非常简单的表,其中包含日期时间列,并且我的域对象中有此映射。
MyDate 是数据库中日期时间列的名称。
public virtual int Day { get; set; }
public virtual int Month { get; set; }
public virtual int Year { get; set; }
public virtual int Hour { get; set; }
public virtual int Minutes { get; set; }
public virtual int Seconds { get;set; }
public virtual int WeekNo { get; set; }
Map(x => x.Day).Formula("DATEPART(day, Datetime)");
Map(x => x.Month).Formula("DATEPART(month, Datetime)");
Map(x => x.Year).Formula("DATEPART(year, Datetime)");
Map(x => x.Hour).Formula("DATEPART(hour, Datetime)");
Map(x => x.Minutes).Formula("DATEPART(minute, Datetime)");
Map(x => x.Seconds).Formula("DATEPART(second, Datetime)");
Map(x => x.WeekNo).Formula("DATEPART(week, Datetime)");
这一切都很好......但是周日期部分。
我看到 NProf 为选择生成了 sql,这就是问题 它正确生成了所有 sql,但对于周日期部分.. 这是生成的 SQL 的一部分:
....Datepart(day, MyDate) ... ....日期部分(月,MyDate)... ....Datepart(年份,MyDate) ... ....日期部分(小时,MyDate)... ....Datepart(分钟, MyDate) ... ....日期部分(第二个,MyDate)... ....Datepart(this_.week, MyDate) ...
其中 this_ 是 nhibernate 使用的表的别名。
所以它将 datepart 的 week 关键字视为一列或类似的东西。澄清一下,没有称为 week 的列或属性。
有帮助吗?
欢呼
亚历山德罗
i have a very simple table with a Datetime column and i have this mapping in my domain object.
MyDate is the name of the datetime column in the DB.
public virtual int Day { get; set; }
public virtual int Month { get; set; }
public virtual int Year { get; set; }
public virtual int Hour { get; set; }
public virtual int Minutes { get; set; }
public virtual int Seconds { get;set; }
public virtual int WeekNo { get; set; }
Map(x => x.Day).Formula("DATEPART(day, Datetime)");
Map(x => x.Month).Formula("DATEPART(month, Datetime)");
Map(x => x.Year).Formula("DATEPART(year, Datetime)");
Map(x => x.Hour).Formula("DATEPART(hour, Datetime)");
Map(x => x.Minutes).Formula("DATEPART(minute, Datetime)");
Map(x => x.Seconds).Formula("DATEPART(second, Datetime)");
Map(x => x.WeekNo).Formula("DATEPART(week, Datetime)");
This is working all great .... but Week Datepart.
I saw with NHProf the sql generating for a select and here's the problem
it's generating all the sql correctly but for week datepart..
this is part of the SQL generated:
....Datepart(day, MyDate) ...
....Datepart(month, MyDate) ...
....Datepart(year, MyDate) ...
....Datepart(hour, MyDate) ...
....Datepart(minute, MyDate) ...
....Datepart(second, MyDate) ...
....Datepart(this_.week, MyDate) ...
where this_ is the alias for the table that nhibernate uses.
so it's treating the week keyword for the datepart stuff as a column or something like that. To clarify there's no column or properties that is called week.
some help ?
cheers
Alessandro
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
前面的内容没有回答问题。将间隔放在引号中应该可以,例如:
Map(x => x.WeekNo).Formula(@"DATEPART(""week"", Datetime)");
The previous doesn't answer the question. Putting the interval in quotes should work, eg:
Map(x => x.WeekNo).Formula(@"DATEPART(""week"", Datetime)");
您没有指定您使用的数据库,所以我假设 SQL Server。尝试以下操作
或
这些是 WEEK 的可接受缩写。
在此处查看更多信息: http://msdn.microsoft.com /en-us/library/aa258265(SQL.80).aspx
You dont specify the DB you use so im assuming SQL Server. Try the following
or
These are accepted abbreviations to WEEK.
Check out more here: http://msdn.microsoft.com/en-us/library/aa258265(SQL.80).aspx