我正在尝试使用自定义DbContext运行迁移.
var migrationConfiguration = new DbMigrationsConfiguration { AutomaticMigrationsEnabled = true };
migrationConfiguration.ContextType = typeof(DataContext);
var migrator = new DbMigrator(migrationConfiguration);
migrator.Update();
Run Code Online (Sandbox Code Playgroud)
这会引发Migration Exception,因为DataContext它没有实现无参数构造函数:
目标上下文'System.Data.Entity.DbContext'不可构造.添加默认构造函数或提供IDbContextFactory的实现.
该DataContext构造函数需要参数,但我已经IDbContextFactory<DataContext>建立.我如何告诉DbMigrator,使用现有的实现IDbContextFactory<DataContext>?
我有以下课程:
class A
{
public:
A();
virtual void doSomething() const;
};
class B : public A
{
public:
B();
void doSomething() const;
};
Run Code Online (Sandbox Code Playgroud)
然后我有功能:
void putToList(const A &a)
{
a.doSomething(); // this one depends on what was set as argument A or B class (putToList(A()) or putToList(B()))
std::list<A> As;
As.push_back(a);
As.back().doSomething(); //this always calls doSomething from A
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,从列表中取出后,对象是A,如果阻止它改变类型,如果传递给函数的对象是B类,则使其成为B.