我有一個ASP.NET MVC2應用程序在.NET 4.0和使用VS 2010,有兩個表(其中),employees
表具有以下列: Firstname,MiddleName, LastName,NationalID,EmployeeType,MobileNumber,Email和UserId。ASP.NET MVC2 Guid持久性問題
userId
字段是來自aspnet_users
表的外鍵,它恰好是一個guid。我試圖堅持所選用戶的員工詳細信息,但因爲出現錯誤而無法完成此操作。
可以使用ViewData字典提取和顯示所選用戶的guid值。 userId
guid值是23aa8cd9-7552-403c-8c99-fcdd611cb188
。
我想將此值與其他員工屬性一起保留,但是當我提交表單時,出現下面顯示的錯誤。 我也使用EF4作爲我的模型。這裏的堆棧跟蹤:
System.Data.UpdateException was unhandled by user code
Message=An error occurred while updating the entries. See the inner exception for details.
Source=System.Data.Entity
StackTrace:
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Objects.ObjectContext.SaveChanges()
at TechDispatch.Models.EmployeeRepository.SaveChanges() in C:\Projects\TechDispatch\TechDispatch\Models\EmployeeRepository.cs:line 131
at TechDispatch.Models.EmployeeRepository.AddNewEmployee(Employee Add) in C:\Projects\TechDispatch\TechDispatch\Models\EmployeeRepository.cs:line 127
at TechDispatch.Controllers.EmployeeController.Create(Employee employee) in C:\Projects\TechDispatch\TechDispatch\Controllers\EmployeeController.cs:line 69
at lambda_method(Closure , ControllerBase , Object[])
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
InnerException: System.Data.SqlClient.SqlException
Message=String or binary data would be truncated.
The statement has been terminated.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=8152
Procedure=""
Server=.
State=13
StackTrace:
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)
InnerException:
任何人都可以請協助?
這個錯誤很可能沒有任何與ASP.NET MVC或。而是它的實體框架/ SQL相關。我建議你改變你的問題標籤,以吸引有關這些領域的知識的讀者。你用什麼數據庫?你沒有提到它。 – Codo 2011-01-30 09:23:16