我正在使用Castle项目ActiveRecord和SqlServer 2008
我想这样做:
ActiveRecordMediator<Question>.FindAll();
但是我收到了这个错误:
SqlDateTime溢出。必须在1/1/1753 12:00:00 AM和12/31/9999 11:59:59 PM之间。
我在sqlServer 2008中使用datetime作为类型。
我也尝试过使用datetime2但得到同样的错误。
THX
更新:
堆栈追踪:
[SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.]
System.Data.SqlTypes.SqlDateTime.FromTimeSpan(TimeSpan value) +4838155
System.Data.SqlTypes.SqlDateTime.FromDateTime(DateTime value) +200
System.Data.SqlClient.MetaType.FromDateTime(DateTime dateTime, Byte cb) +46
System.Data.SqlClient.TdsParser.WriteValue(Object value, MetaType type, Byte scale, Int32 actualLength, Int32 encodingByteSize, Int32 offset, TdsParserStateObject stateObj) +4843589
System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc) +4291
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +175
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137
NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd) +303
NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation) +65
NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session) +1895
NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session) +307
NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, Object rowId, ISessionImplementor session) +1029
NHibernate.Action.EntityUpdateAction.Execute() +740
NHibernate.Engine.ActionQueue.Execute(IExecutable executable) +187
NHibernate.Engine.ActionQueue.ExecuteActions(IList list) +125
NHibernate.Engine.ActionQueue.ExecuteActions() +50
NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) +162
NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) +102
NHibernate.Impl.SessionImpl.Flush() +297
Castle.ActiveRecord.Framework.SessionFactoryHolder.ReleaseSession(ISession session) in c:\daten\dev\External\Castle\AR2.0\ActiveRecord\Castle.ActiveRecord\Framework\SessionFactoryHolder.cs:257
Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType, Order[] orders, ICriterion[] criteria) in c:\daten\dev\External\Castle\AR2.0\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordBase.cs:1026
Castle.ActiveRecord.ActiveRecordMediator.FindAll(Type targetType, Order[] orders, ICriterion[] criterias) in c:\daten\dev\External\Castle\AR2.0\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordMediator.cs:193
Castle.ActiveRecord.ActiveRecordMediator.FindAll(Type targetType) in c:\daten\dev\External\Castle\AR2.0\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordMediator.cs:180
Castle.ActiveRecord.ActiveRecordMediator`1.FindAll() in c:\daten\dev\External\Castle\AR2.0\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordMediator.Generic.cs:153
StackUnderflow.Persistence.Repositories.QuestionsRepository.GetNewestQuestions(Int32 numberOfQuestions) in C:\Users\Anas\Documents\Visual Studio 2010\Projects\StackUnderflow\StackUnderflow.Persistence\Repositories\QuestionsRepository.cs:24
StackUnderflow.Persistence.RichRepositories.RichQuestionRepository.GetNewestQuestions(Int32 numberOfQuestions) in C:\Users\Anas\Documents\Visual Studio 2010\Projects\StackUnderflow\StackUnderflow.Persistence\RichRepositories\RichQuestionRepository.cs:47
StackUnderflow.Web.Ui.Controllers.HomeController.Index() in C:\Users\Anas\Documents\Visual Studio 2010\Projects\StackUnderflow\StackUnderflow.Web.Ui\Controllers\HomeController.cs:21
lambda_method(ExecutionScope , ControllerBase , Object[] ) +74
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +52
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +254
System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +192
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +314
System.Web.Mvc.Controller.ExecuteCore() +105
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +39
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +34
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +59
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +44
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8682542
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
答案 0 :(得分:2)
问题类是否具有DateTime类型属性?如果确实如此,并且它未设置为可空,则在实例化类时,将分配默认的datetime值,即01.01.01。这将导致sql异常。