我想启动OnModel创建每个new DataContext(new Entity())
... 但是,当我创建一个表的连接,它的工作原理。当创建另一个表的连接,再次OnModelCreating行不通的,所以因为我也有错误,如何强制启动OnModel创建每个DataContext初始化
the entity type <tableName> is not part of the model for the current context.
public class DataContext : DbContext
{
private BaseEntity _entity;
public DataContext(BaseEntity entity)
{
Database.Connection.ConnectionString = Parameters.ConnectionString;
_entity = entity;
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
_entity.Map(modelBuilder); // this is dynamic fluent api here
}
}
我不能使用通用的,不适用于我的项目。工作单元将其封锁在我的项目中。这个用法现在对我更有用。 –
当我有一个db操作时,我已经为每个实体创建了DataContext。但是在首次创建datacontext之后,onmodel配置不再起作用。但我必须改变流利的API,所以我必须开启模式创建。 –
有没有办法在运行时为DbModelBuilder运行流畅的api? –