Sunday, September 14, 2014

Entity Framework 5 to 6 Conversion Error - Cannot implicitly convert type 'System.Data.EntityState' to 'System.Data.Entity.EntityState'. An explicit conversion exists (are you missing a cast?)

Problem scenario:

Entity Framework 5 to 6 Conversion Error - Cannot implicitly convert type 'System.Data.EntityState' to 'System.Data.Entity.EntityState'. An explicit conversion exists (are you missing a cast?)

Solution:

When you are using EF 6 or moving from EF 5 to EF 6, you should use System.Data.Entity.EntityState instead of System.Data.EntityState. This error happens when your project has reference to EF6 but you have code for EF5.

Sample Code in EF6

public virtual void Update(T entity)
{
   dbSet.Attach(entity);
   _unitOfWork.Db.Entry(entity).State = System.Data.Entity.EntityState.Modified;
   this._unitOfWork.Db.SaveChanges();
}

No comments:

VS Code # Warning - npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead

Error : VS Code - NPM Warning - npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead Solution:  Foll...