'The name 'EntityState' does not exist in the current context

In Entity Framework, this sometimes occurs when the System.data.entity assembly is not added into the Project. But, why I didn't have this error before in other MVC project.

it occurs sometimes but frequently and I have to add it manually in Add References. What can I do?



Solution 1:[1]

I fixed this issue as below

Namespace

using System.Data;
using System.Data.Entity;

I was working earlier in ASP.Net MVC C# application working fine for me. I fixed this issue as below

using System.Data;

I was working earlier in ASP.Net MVC C# application working fine for me

_context.Entry(_Teach).State = System.Data.EntityState.Modified;

Now, same method using in simple c#, WCF but it giving me issue then I did this in a way as below:

_context.Entry(_Teach).State = EntityState.Modified;

Solution 2:[2]

Try changing

e.g.

System.Data.EntityState.Modified;

to

System.Data.Entity.EntityState.Modified;

(Not sure what's going on. Did Microsoft change the package?)

Solution 3:[3]

I fixed this problem by including the namespace it's from:

using System.Data.Entity;

Solution 4:[4]

When I had this problem, I fixed it by including the namespace it's from:

using System.Data;

More info:

http://msdn.microsoft.com/en-us/library/system.data.entitystate.aspx

Solution 5:[5]

This was resolved for me when I added

using Microsoft.EntityFrameworkCore;

Maybe that will work?

Solution 6:[6]

You should make changes as below in code.

 public ActionResult Edit(Album album)
    {
        if (ModelState.IsValid)
        {
            db.Entry(album).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        ViewBag.ArtistId = new SelectList(db.Artist, "ArtistId", "Name", album.ArtistId);
        ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
        return View(album);
    }

Solution 7:[7]

Make sure you have added reference to System.Data.Entity

Right click on "References" under your project library > Add Reference...

Make sure you have added reference to System.Data.Entity

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anjan Kant
Solution 2 robor
Solution 3 tiepnv
Solution 4 twelveFunKeys
Solution 5 glitchwizard
Solution 6 Kalu Singh Rao
Solution 7 Sumit Joshi