MarkKGreenway
MarkKGreenway

Reputation: 8764

C# inheritance and interfaces confusion

I am trying to use fakes for EF 4.1 DataContext to test the repository without testing the database ( due to a deployment issue)

I am doing something like this

public interface IEmployeeContext
{
    IDbSet<Department> Departments { get; }
    IDbSet<Employee> Employees { get; }
    int SaveChanges();
}

public class EmployeeContext : DbContext, IEmployeeContext
{
    public IDbSet<Department> Departments { get; set; }
    public IDbSet<Employee> Employees { get; set; }
}

public class FakeEmployeeContext : IEmployeeContext
{
    public IDbSet<Department> Departments { get; set; }
    public IDbSet<Employee> Employees { get; set; }
    public FakeEmployeeContext ()
    {
        Departments = new FakeDbSet<Department>();
        Employees = new FakeDbSet<Employee>();
    }
}

which works great most of the time but my problem is that sometimes in my code i use things like :

context.Entry(department).State  = EntityState.Modified;

and it complains that

'IEmployeeContext' does not contain a definition for 'Entry'

I cannot seem to comprehend what i need to change in the pattern to allow me access to the context.Entry and context.Database sections

Upvotes: 0

Views: 258

Answers (1)

Daniel Mann
Daniel Mann

Reputation: 59055

The reason you're getting that specific error is because IEmployeeContext doesn't contain a method called Entry.

Entry is a member of DbContext.

Upvotes: 1

Related Questions