简体   繁体   English

在迁移时在实体框架的dbset中使用通用时

[英]When using generic in the dbset of the entity framework at Migration

I made this change, before it was like this 我做了这样的改变,才是这样

    public DbSet<Pessoa> Pessoas { get; set; }

Now it's this way 现在就是这样

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());                          

        }
}        

So now I do not know what I do in class migrations 所以现在我不知道我在课堂迁移中做什么

internal sealed class Configuration : DbMigrationsConfiguration<local.blogapi.Context.ContextData
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
    }

    protected override void Seed(local.blogapi.Context.ContextData context)
    {

    }
}

I know it's going to make a mistake. 我知道这会出错。 I do not know how to get the entities or if there is any specific command at the time of doing the migration, or if I pass some interface, such as IEntity 我不知道如何获取实体,或者在进行迁移时是否有任何特定的命令,或者我是否传递了某些接口,例如IEntity

you're probably wrong. 你可能是错的。

A context is a group of dbset (dbsets represent sql tables), read this . 上下文是一组dbset(dbset代表sql表),请阅读this

I think that you don't need one context for every table in your db. 我认为您不需要为数据库中的每个表提供一个上下文。 Use of more contexts may make sense if you want to separate dbsets that have different logic (based on the schema for example, or to separate read / write tables) 如果要分离具有不同逻辑的dbset(例如,基于模式,或分离读/写表),则可以使用更多上下文

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM