相关疑难解决方法(0)

EF Core 在每次迁移时更新种子数据而无需更改

所以我用这样的用户和角色来播种我的数据库。

public static void SeedUsers(this ModelBuilder modelBuilder)
    {
        var roles = new[]
        {
            new Role
            {
                Id = new Guid("5127599a-e956-4f5e-9385-1b8c6a74e4f1"),
                RoleName = "Customer"
            },
            new Role
            {
                Id = new Guid("8634c476-20fa-4391-b8f7-8713abf61af0"),
                RoleName = "Admin"
            }
        };

        // customer password
        byte[] customerPasswordHash = null;
        byte[] customerPasswordSalt = null;
        HashPassword("asd123", out customerPasswordHash, out customerPasswordSalt);

        // admin password
        byte[] adminPasswordHash = null;
        byte[] adminPasswordSalt = null;
        HashPassword("asd123", out adminPasswordHash, out adminPasswordSalt);
        var users = new[]
        {
            new Users()
            {
                Id = new Guid("3b86f5a2-1978-46e3-a0b6-edbb6b558efc"), …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core .net-core ef-core-2.0 entity-framework-migrations

8
推荐指数
1
解决办法
1334
查看次数