我试图用假货的EF 4.1 DataContext的测试库,而不会测试数据库(由于部署问题)C#继承和接口混乱
我做这样的事情
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>();
}
}
它的伟大工程的大部分时间,但我的问题是,有时在我的代码我使用的东西,如:
context.Entry(department).State = EntityState.Modified;
,并抱怨说,
“IEmployeeContext”不包含定义“进入”
我似乎无法理解我需要的模式改变,让我获得了context.Entry和context.Database部分
你可以显示“context”声明的代码吗? – CesarGon
你如何申报上下文? – Alan
这是铸造相关的问题吗? 'IEmployeeContext'没有定义'Entry'属性/函数,而是定义在'DbContext'类中。 '((IEmployeeContext)context).Entry(department).State ..'可能会解决你的问题。 –