1

我有一堆实体,在 SQL 中有数百个字段,其中几十个是不可为空的。我希望创建实体,保存并查看它抱怨的字段,以便我可以轻松地包含它(使用单元测试非常快速/容易做到),但是我从 EF 获得的信息不显示哪个字段/属性导致错误?为什么会这样?我什至尝试/捕获,输出异常并且没有关于问题的其他信息:-(

System.Data.UpdateException : An error occurred while updating the entries. See the inner exception for details.
  ----> System.Data.SqlTypes.SqlTypeException : SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
   at PaymentDomain.IntegrationTests.EFTestSetup.Test() in EFTestSetup.cs: line 40
--SqlTypeException
   at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc, Boolean sync, TaskCompletionSource`1 completion, Int32 startRpc, Int32 startParam)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, ref Task task, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, ref Task task, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
   at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)

酷,怎么样:CreateDate

谢谢...

4

1 回答 1

0

您可以使用DbContext.GetValidationErrors()方法来检索验证规则中断信息。MSDN 上的文章

于 2013-06-25T21:10:48.953 回答