Here's the background: I built a new WCF service which uses EF5 and was targeting .Net Framework 4.5. I've used code-first against an existing large legacy database. All was working nicely until I came to deploy the service to a test server, when I discovered the test server (and therefore the production server since they are the same build) was not capable of supporting Framework 4.5.
So, I downgraded the project to target Framework 4.0. After re-coding all my entity mappings (to avoid using code in the DataAnnotations.Schema namespace specific to 4.5), I had this working again locally. However, after deploying to the server I was hitting the error described here: Can anyone spot why I keep getting this error testing the EF 5 beta.
After doing as suggested - uninstalling and re-installing EF5 via NuGet, I am now getting a timeout error when trying to test the service.
Specifically the timeout occurs when attempting to execute the following 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
};
There may well be a more efficient way to write this query - I'm fairly inexperienced with Linq and EF, but I would stress this did NOT time-out prior to the uninstall and re-install of EF. In fact it returned data fairly quickly.
I can't see any reason this would timeout after the re-install of EF, nothing in the code has changed, but need a solution to this fast!
Thanks.
To clarify the error I'm getting, it's at the point that EF tries to execute the above query, I get an EntityCommandExecutionException thrown. The exception message is "An error occurred while executing the command definition. See the inner exception for details." The inner exception is "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."
The stack trace is below:
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
at System.Data.Objects.ObjectQuery1.GetResults(Nullable
1 forMergeOption)
at System.Data.Objects.ObjectQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Data.Entity.Internal.Linq.InternalQuery
1.GetEnumerator()
at System.Data.Entity.Infrastructure.DbQuery1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
at RepeatBillingService.Repositories.BillingRepository.GetMembersForGame(String game, List
1& billingQ) in p:\Projects\BigFatLottos\RepeatBillingService\RepeatBillingService\Repositories\BillingRepository.cs:line 441
at RepeatBillingService.Repositories.BillingRepository.GetMemberGamesForBilling() in p:\Projects\BigFatLottos\RepeatBillingService\RepeatBillingService\Repositories\BillingRepository.cs:line 24
at RepeatBillingService.RepeatBillingService.RunRepeatBilling() in p:\Projects\BigFatLottos\RepeatBillingService\RepeatBillingService\RepeatBillingService.svc.cs:line 51
at SyncInvokeRunRepeatBilling(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)