DbContext SaveChangesAsync Exception

时间:2014-07-27 14:53:23

标签: asp.net-mvc entity-framework c#-4.0 asynchronous dbcontext

我想换个新车,因为我有这个代码:

using (var db = new CarManagerDbEntities())
            {
                Guid? carId = GetCarId(carLicenceId);
                if (carId == null)
                {
                    return null;
                }
                Guid rideId = Guid.NewGuid();
                Ride newRide = new Ride() { DriverID = driverId, CarID = carId.Value, StartDrive= startTime, Id = rideId};
                db.Ride.Add(newRide);
                await db.SaveChangesAsync();
                return carId;
            } 

但是在行中:

  

等待db.SaveChangesAsync();

我得到了这个例外:

System.ServiceModel.FaultException`1 was unhandled
  HResult=-2146233087
  Message=An error occurred while updating the entries. See the inner exception for details.
  Source=mscorlib

堆栈跟踪:

    Server stack trace: 
       at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at CarManager.TestingCLI.CarManagerServiceReference.ICarManagerApi.StartNewRide(Guid driverId, DateTime startTime, String carLicenceId)
       at CarManager.TestingCLI.CarManagerServiceReference.CarManagerApiClient.StartNewRide(Guid driverId, DateTime startTime, String carLicenceId) in c:\Projetcs\CarManager.TestingCLI\Service References\CarManagerServiceReference\Reference.cs:line 990
       at CarManager.TestingCLI.Program.Main(String[] args) in c:\Projetcs\CarManager.TestingCLI\Program.cs:line 17
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

内部异常为空。

我做得不对?

0 个答案:

没有答案