首先:我已将NHibernate
从版本2.1.2.400
升级为4.0.4.400
我有一个struct
来实现一些运算符。
public struct YearAndMonth{
private int _month;
/// <summary>
/// Month, between 1 and 12.
/// </summary>
public int Month
{
get
{
if (_month == 0)
{
_month = 1;
}
return _month;
}
private set // for NHibernate
{
if (value < 1 || value > 12)
{
throw new ArgumentOutOfRangeException("value");
}
_month = value;
}
}
private int _year;
/// <summary>
/// Year, between 1 and 9999.
/// </summary>
public int Year
{
get
{
if (_year == 0)
{
_year = 1;
}
return _year;
}
private set // for NHibernate
{
if (value < 1 || value > 9999)
{
throw new ArgumentOutOfRangeException("value");
}
_year = value;
}
}
public static bool operator >=(YearAndMonth obj1, YearAndMonth obj2)
{
if (obj1.Year == obj2.Year )
{
return (obj1.Month >= obj2.Month);
}
return (obj1.Year >= obj2.Year);
}
}
我的课看起来有点像这样:
class MyObj {
public YearAndMonth Period {get; set;}
}
我有这样的where
声明:
.Where(_ => _.Period >= startPeriod && _.Period <= endPeriod)
当NHibernate
转换where
语句时,它会生成奇怪的SQL并抛出GenericADOException
:
WHERE (
myobj0_.periodmonth ge @p0
AND myobj0_.periodyear ge @p1)
AND (
myobj0_.periodmonth le @p2
AND myobj0_.periodyear le @p3)
如何在不修改Linq
语句的情况下使我的where语句正常工作?
NHibernate
2.1.2.400
与NHibernate.Linq
1.1.0.1001
生成的声明:
WHERE (
this_.periodmonth >= @p0
AND this_.periodyear >= @p1
AND this_.periodmonth <= @p2
AND this_.periodyear <= @p3)