A simpler approach is:
bool isDetached = context.Entry(user).State == EntityState.Detached;
if (isDetached)
context.Users.Attach(user);
More Related Contents:
- Entity Framework and Connection Pooling
- Entity Framework vs LINQ to SQL
- Like Operator in Entity Framework?
- Fake DbContext of Entity Framework 4.1 to Test
- How can I query for null values in entity framework?
- Entity Framework: table without primary key
- .NET Entity Framework and transactions
- Get Database Table Name from Entity Framework MetaData
- Can you use Microsoft Entity Framework with Oracle? [closed]
- How do I enable EF migrations for multiple contexts to separate databases?
- “Items collection must be empty before using ItemsSource.”
- Using Entity Framework (code first) migrations in production
- Does Entity Framework support parallel async queries? [duplicate]
- How to make Entity Framework Data Context Readonly
- Generate POCO classes in different project to the project with Entity Framework model
- The repository itself is not usually tested?
- What are Navigation Properties in Entity Framework for?
- LINQ to Entities does not recognize the method Int32 get_Item(Int32)
- How to set default value for POCO’s in EF CF?
- How to map table splitting in EF Code First?
- Start a Task in the Form Shown event
- Organizationally, where should I put common queries when using Entity Framework Code First?
- Entity Framework is Too Slow. What are my options? [closed]
- Using entity framework on multiple databases
- entity framework Unable to load the specified metadata resource [duplicate]
- How can I configure Entity Framework to automatically trim values retrieved for specific columns mapped to char(N) fields?
- The model backing the ‘ApplicationDbContext’ context has changed since the database was created
- Entity Framework Find vs. Where
- ‘ObjectContext’ vs ‘DbContext’ in Entity Framework
- Using Entity Framework entities as business objects?