[英]Entity Framework Core 3, Define DBSet for query but dont create migration entry
[英]When using generic in the dbset of the entity framework at Migration
我做了这样的改变,才是这样
public DbSet<Pessoa> Pessoas { get; set; }
现在就是这样
class ContextData<T> : DbContext where T : class
{
public DbSet<T> Dbset { get; set; }
public ContextData() : base("name=Connection")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Configurations.Add(new PessoaMapping());
}
}
所以现在我不知道我在课堂迁移中做什么
internal sealed class Configuration : DbMigrationsConfiguration<local.blogapi.Context.ContextData
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
protected override void Seed(local.blogapi.Context.ContextData context)
{
}
}
我知道这会出错。 我不知道如何获取实体,或者在进行迁移时是否有任何特定的命令,或者我是否传递了某些接口,例如IEntity
你可能是错的。
上下文是一组dbset(dbset代表sql表),请阅读this 。
我认为您不需要为数据库中的每个表提供一个上下文。 如果要分离具有不同逻辑的dbset(例如,基于模式,或分离读/写表),则可以使用更多上下文
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.