Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 278
JMJ Avatar asked Jul 25 '13 09:07

JMJ


People also ask

What is Entitystate?

EF API maintains the state of each entity during its lifetime. Each entity has a state based on the operation performed on it via the context class. The entity state represented by an enum System.

How do you reference a System data entity?

dll: right-click the Reference node of your project form Solution Explorer, select Add Reference, on the pop up dialog, navigate to . NET tab, choose System. Data. Entity from the Component Name listbox.


1 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;
like image 73
Anjan Kant Avatar answered Sep 19 '22 21:09

Anjan Kant