nhibernate how to find bad field in complex update

I am saving a complex object tree back to my sql server database. one of the fields on the object tree must be a null or a funny date because I get this error message.

"SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."

I can find it by using visual studios inspector and drill down until I find the dodgy field, but this is very time consuming. Also it doesn't led itself to a great logging error message.

Is their a way I can get nhibernate to return the offending field name with the error message?

I am not doing anything fancy,

public TEntity Save(TEntity entity)
    {
        return Save(entity, false);
    }

note: I am using fluent nhibernate to configure


NHibernate不会告诉你哪个字段导致了这种情况,但是很容易缩小范围:99%的确定性,它是一个不可初始化的不可空的 DateTime字段,所以它的默认值为1/1/1( IIRC),这显然超出了范围。


I can't speak for SQL Server, but with SQLite, the name of the offending field is often shown, but buried so deeply in the exception message or inner exceptions that it is very easy to miss.

It may be valuable to simply call the exception's ToString() method, which will create a single string containing all message text, including all inner exceptions, and show it in a message box.

Or, type the following in the Immediate Window, eg

Debug.Print( ex.ToString() )

When you can see it all at once, you may find what you need buried in the middle somewhere.

链接地址: http://www.djcxy.com/p/26968.html

上一篇: 保存smalldatetime字段

下一篇: nhibernate如何在复杂更新中找到不良域