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?

Answers


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;

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?)


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

using System.Data.Entity;


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


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);
    }

This was resolved for me when I added

using Microsoft.EntityFrameworkCore;

Maybe that will work?


Need Your Help

Convert Array to Object

javascript arrays node.js object

What is the best way to convert:

Random alpha-numeric string in JavaScript?

javascript random

What's the shortest way (within reason) to generate a random alpha-numeric (uppercase, lowercase, and numbers) string in JavaScript to use as a probably-unique identifier?