Frage

I am trying to create a generic repository with EF using a base class called BaseRepository. My update method will not work though for a strange reason. Code is as follows

public void UpdateItem(T item)
{
    _context.Entry(item).State = EntityState.Modified;
}

When I try and debug my test method, it won't even step into the UpdateItem() method even if I have a break point prior to the only line of code being executed. As soon as I try to step into the method it throws the following error

MissingMethodException - Method not found: 'Void System.Data.Entity.Infrastructure.DbEntityEntry'1.set_State (System.Data.EntityState)

It compiles fine but it errors at run-time.

Does anyone have any thoughts?

War es hilfreich?

Lösung

The error is a missing Method exception. There is a Method that the Runtime is not able to find.

If it was some Method in an Interface that was not implemented, you would get a compile time error.

Therefore, it is probable an extension Method that is in a dll that is not referenced in Your Project.

You need to add the EF Nuget package to Your Project instead of referencing the dll's via add Reference.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top