[英]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) 我正在尝试对EF 4.1 DataContext使用伪造品来测试存储库而不测试数据库(由于部署问题)
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' “ IEmployeeContext”不包含“条目”的定义
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 我似乎无法理解我需要更改模式以允许我访问context.Entry和context.Database部分的内容
The reason you're getting that specific error is because IEmployeeContext
doesn't contain a method called Entry
. 您收到该特定错误的原因是因为
IEmployeeContext
不包含名为Entry
的方法。
Entry
is a member of DbContext
. Entry
是DbContext
的成员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.