EF 7 Migrations with multiple DBContexts

后端 未结 3 1541
夕颜
夕颜 2021-01-06 14:15

I have a problem scaffolding and doing migrations from a class library with multiple DBContexts. I found a command line argument that looks like this for migrations:

3条回答
  •  天命终不由人
    2021-01-06 14:54

    I haven't tried putting the data-layer in a separate project yet, but I do have multiple DbContexts in a single Web API project. It should work with separate projects too.

    Using the latest syntax (v1.0.0), you create your migrations like this:

    dotnet ef migrations add  -o  -c 
    

    Where is the full class-name of your DbContext -- like MyProject.Data.MyDbContext

    I put my migrations for different contexts into different directories, but I don't think you have to. Just make sure they have different migration-name values.

提交回复
热议问题