Jobayer Ahmmed Jobayer Ahmmed - 1 year ago 147
C# Question

Can not find DbUpdateConcurrencyException Entries.Single() method in mvc

I am following Tom Dykstra's "Getting Started with Entity Framework 6 Code First using MVC 5" tutorial.
In concurrency handling part, I can not use the Single() method at Entries. It says-

"System.Collections.Generic.IEnumarable does not contain a definition for 'Single' and no extension method 'Single' accepting a first argument of type 'System.Collections.Generic.IEnumarable' could be found (are you missing a using directive or an assembly referrence?)"

Here is the code-

using System;
using System.Data.Entity;
using System.Threading.Tasks;
using System.Net;
using System.Web.Mvc;
using ContosoUniversity.DAL;
using ContosoUniversity.Models;
using System.Data.Entity.Infrastructure;


catch (DbUpdateConcurrencyException ex)
var entry = ex.Entries.Single();
var clientValues = (Department)entry.Entity();
var databaseEntry = entry.GetDatabaseValues();

Answer Source

You have to add using System.Linq

Enumerable.Single has the namespace System.Linq

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download