开发者

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>();
        E开发者_JS百科mployees = 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


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

Entry is a member of DbContext.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜