我有一個實體框架的問題。特別是我不能做插入或更新操作。 錯誤消息:實體框架插入更新問題!
An error occurred while updating the entries. See the inner exception for details.System.Data.SqlClient.SqlException (0x80131904): The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
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.Common.DbCommand.ExecuteReader(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)
你能幫我嗎?
樣品的編號:
ProductGroups group;
if (txtProductGroupName.Text.Trim() != null)
{
group = new ProductGroups();
group.ProductGroupName = txtProductGroupName.Text.Trim();
context.ProductGroups.AddObject(group);
context.SaveChanges();
context.AcceptAllChanges();
lblState.ForeColor = Color.Red;
lblState.Text = "Ürün grubu kaydedildi...";
}
else
{
lblState.ForeColor = Color.Red;
lblState.Text = "Ürün grubu ismini bos geçmeyiniz";
}
的ProductGroups表與5列定義:
- [ProductGroupID] INT
- [ProductGroupName] VARCHAR(100)
- [ProductGroupComment] VARCHAR (1000)
- [CreatedOn] datetime
- [DeletedOn]日期時間
您可以發佈失敗的示例代碼嗎?此外,這應該給你一個提示:**將datetime2數據類型轉換爲日期時間數據類型導致超出範圍的值。** – BrokenGlass 2011-03-10 07:38:27
可能,您正在給出DateTime。MinValue()到某處,它不在實體結構的範圍內。 – 2011-03-10 08:37:44