NHibernate将> =转换为GE并使用自定义运算符在对象上抛出GenericADOException

时间:2016-04-15 08:42:44

标签: c# nhibernate

首先:我已将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.400NHibernate.Linq 1.1.0.1001生成的声明:

WHERE           ( 
                                            this_.periodmonth  >= @p0 
                            AND             this_.periodyear >= @p1 
                            AND             this_.periodmonth <= @p2 
                            AND             this_.periodyear <= @p3)

0 个答案:

没有答案