2012-10-13 40 views
0

以下是背景:我構建了一個新的WCF服務,它使用EF5並以.Net Framework 4.5爲目標。我已經使用代碼優先對現有的大型遺留數據庫。直到我將服務部署到測試服務器時,我發現測試服務器(因此它們是相同版本的生產服務器)無法支持Framework 4.5,所有這些工作都很好。更改目標框架版本並重新安裝EF實體框架5命令超時錯誤EF

因此,我將該項目降級爲Framework 4.0。在對我所有的實體映射進行重新編碼之後(爲了避免使用特定於4.5的DataAnnotations.Schema命名空間中的代碼),我在本地再次執行了此操作。但是,在部署到服務器之後,我遇到了此處描述的錯誤:Can anyone spot why I keep getting this error testing the EF 5 beta

按照建議進行操作後 - 通過NuGet卸載並重新安裝EF5,現在在嘗試測試服務時出現超時錯誤。

試圖執行以下的Linq時具體發生超時:

var games = from m in _db.Members 
     join s in _db.UkSyndicates 
      on m.MemberId equals s.MemberId 
     where m.PaymentMethod == "Credit/Debit Card" 
     && EntityFunctions.TruncateTime(s.NextChargeDate) <= EntityFunctions.TruncateTime(DateTime.Now) 
     && !string.IsNullOrEmpty(m.AibCustomerReference) 
     && (m.StatusId == 105 || m.StatusId == 113) 
     select new BillingItem 
     { 
      Id = s.Id, 
      SyndicateId = s.SyndicateId, 
      MemberId = s.MemberId, 
      LastDrawId = s.LastDrawId, 
      LastPaidGame = s.LastPaidGame, 
      NextChargeDate = s.NextChargeDate, 
      Protected = s.Protected, 
      PaymentFrequency = (int)(s.PaymentFrequency*4), 
      CurrencyCode = m.CurrencyCode, 
      AibCustomerReference = m.AibCustomerReference, 
      WeeklyFee = (from f in _db.GameFees where f.FeeName == "UK_LOTTO_FEE" && f.CurrencyCode == m.CurrencyCode select f.Amount).FirstOrDefault(), 
      GameCode = game, 
      PostCode = m.PostCode, 
      CountryCode = m.CountryCode, 
      EmailAddress = m.Email 
     }; 

有可能是寫這個查詢更有效的方式 - 我與LINQ和EF相當缺乏經驗,但我要強調這在EF卸載和重新安裝之前沒有超時。事實上,它很快就會返回數據。

我看不出任何原因,這將重新安裝EF後超時,代碼中沒有任何更改,但需要一個解決方案,以此快!

謝謝。

爲了澄清我得到的錯誤,在EF嘗試執行上述查詢時,我得到一個EntityCommandExecutionException拋出異常。異常消息是「執行命令定義時發生錯誤,詳情請參閱內部異常。」內部異常是「超時過期,操作完成之前已超時或服務器沒有響應。」

堆棧跟蹤低於:

在System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,的CommandBehavior行爲) 在System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute [TResultType](ObjectContext的上下文,ObjectParameterCollection的parameterValues) 在System.Data.Objects.ObjectQuery 1.GetResults(Nullable 1個forMergeOption) 在System.Data.Objects.ObjectQuery 1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Data.Entity.Internal.Linq.InternalQuery 1.GetEnumerator() 在System.Data.Entity.Infrastructure.DbQuery billingQ)的對:\項目\ BigFatLottos \ RepeatBillingSe在RepeatBillingService.RepeatBillingService.RunRepeatBilling上的RepeatBillingService.Repositories.BillingRepository.GetMemberGamesForBilling()中的rvice \ RepeatBillingService \ Repositories \ BillingRepository.cs:第441行 :p:\ Projects \ BigFatLottos \ RepeatBillingService \ RepeatBillingService \ Repositories \ BillingRepository.cs:行24 ()在p:\ Projects \ BigFatLottos \ RepeatBillingService \ RepeatBillingService \ RepeatBillingService.svc.cs中:第51行 在SyncInvokeRunRepeatBilling(Object,Object [],Object []) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance ,Object [] inputs,Object [] & outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime。InvokeBegin(MessageRpc & rpc)

+0

爲什麼先對現有數據庫進行coode-first?當然,自然的選擇首先是數據庫?對我來說這似乎很奇怪,雖然這不是我第一次看到這個決定...... –

+0

什麼是超時?數據庫或服務? –

+0

@flem感謝您的回覆。數據庫是一個巨大的遺留問題,充滿了命名不佳的列等。對於這個特定的工作,我只需要大約15個表,所以想寫出「乾淨的」實體並將它們映射到所需的表。因此,代碼優先似乎是要走的路 - 但也許有更好的方法,正如我所說我對EF很新。 – PeteM

回答

1

我已經深究了這一點,並且道歉,因爲整個問題都是一些紅鯡魚。我在後臺打開了一個SSMS會話,在那裏我正在調整數據進行測試,並且一直在更新「NextChargeDate」值。當我關閉會議時,我得到了「有未交付的交易,你現在要做什麼」,這開始警鐘響了。

果然在重新啓動WCF服務時,一切正常。所以我的超時發生是因爲數據庫中該字段的未提交更新 - EF在提交更新之前顯然無法成功讀取數據。

因此,我很抱歉浪費你的時間與這個問題,只是一個簡單的疏忽,同時在壓力下長時間工作以獲得新系統的生活。

無論如何感謝您的回覆。