使用 Fluent 迁移器将初始行添加到表中

adding initial rows into tables using Fluent migrator

我是一名典型的程序员,在泛型方面是新手,这是一个 asp.net MVC5 示例应用程序,用于学习使用流畅的迁移器库集成授权 (users/roles)。我想在表创建时将一些示例数据添加到表中(使用迁移器控制台工具)。

出现编译错误:USERNAME 在当前上下文中不存在
我应该在使用部分或以下任何示例中添加什么: Insert.IntoTable 方法 ?

(谢谢)

namespace SampleApp.Migrations
{
    [Migration(1)]
    public class AuthMigrations:Migration
    {
        public override void Up()
        {
            Create.Table("users").
                WithColumn("ID").AsInt32().Identity().PrimaryKey().
                WithColumn("USERNAME").AsString(128).
                WithColumn("EMAIL").AsCustom("VARCHAR(128)").
                WithColumn("PASSWORD_HASH").AsString(128);

            Create.Table("roles").
                WithColumn("ID").AsInt32().Identity().PrimaryKey().
                WithColumn("NAME").AsString(128);

            Create.Table("role_users").
                WithColumn("ID").AsInt32().Identity().PrimaryKey().
                WithColumn("USER_ID").AsInt32().ForeignKey("users", "ID").OnDelete(Rule.Cascade).
                WithColumn("ROLE_ID").AsInt32().ForeignKey("roles", "ID").OnDelete(Rule.Cascade);

            //Error:The name 'USERNAME' does not exist in the current context

            Insert.IntoTable("users").Row(new { USERNAME:"superadmin",EMAIL:"superadmin@mvcapp.com",PASSWORD_HASH:"dfgkmdglkdmfg34532+"});
            Insert.IntoTable("users").Row(new { USERNAME:"admin",EMAIL:"admin@mvcapp.com",PASSWORD_HASH:"dfgkmdglkdmfg34532+"});
        }

        public override void Down()
        {
            Delete.Table("role_users");
            Delete.Table("roles");
            Delete.Table("users");
        }

    }

 namespace SampleApp.Models
{
    public class User
    {
        public virtual int Id { get; set; }
        public virtual string Username { get; set; }
        public virtual string EMail { get; set; }
        public virtual string passwordhash { get; set; }
    }

    public class UserMap : ClassMapping<User>
    {
        public UserMap()
        {
            Table("Users");
            Id(x => x.Id, x => x.Generator(Generators.Identity));
            Property(x => x.Username, x => x.NotNullable(true));
            Property(x => x.EMail, x => x.NotNullable(true));
            Property(x=>x.passwordhash,x=>
            {
                x.Column("PASSWORD_HASH");
                x.NotNullable(true);
            });
        }
    }
}

在 C# 中,您必须在对象初始值设定项中使用等号(“=”)而不是冒号(“:”)。

Insert.IntoTable("users").Row(new { USERNAME = "superadmin",EMAIL = "superadmin@mvcapp.com",PASSWORD_HASH = "dfgkmdglkdmfg34532+"});
Insert.IntoTable("users").Row(new { USERNAME = "admin",EMAIL = "admin@mvcapp.com",PASSWORD_HASH = "dfgkmdglkdmfg34532+"});