1

既存のデータベースで最初に ef コードを使用して移行を行うときに、テーブル名を変更しようとすると問題が発生します。既存のデータベースで「Cities」というテーブル名を取得しましたが、「City」に変更したいと考えています。マッピングファイルで、私は宣言します:

public CityMap()
    {
        // Primary Key
        this.HasKey(t => t.CityId);

        // Properties
        this.Property(t => t.CityCode)
            .HasMaxLength(64);

        this.Property(t => t.Name)
            .HasMaxLength(128);

        this.Property(t => t.SysNo)
            .HasMaxLength(64);

        this.Property(t => t.No_Ins)
            .HasMaxLength(64);

        this.Property(t => t.CountryCode)
            .HasMaxLength(64);

        // Table & Column Mappings
        this.ToTable("City");
        this.Property(t => t.CityId).HasColumnName("CityId");
        this.Property(t => t.CityCode).HasColumnName("CityCode");
        this.Property(t => t.Name).HasColumnName("Name");
        this.Property(t => t.SysNo).HasColumnName("SysNo");
        this.Property(t => t.No_Ins).HasColumnName("No.Ins");
        this.Property(t => t.CountryId).HasColumnName("CountryId");
        this.Property(t => t.CountryCode).HasColumnName("CountryCode");
        this.Property(t => t.Note).HasColumnName("Note");

        // Relationships
        this.HasRequired(t => t.Country)
            .WithMany(t => t.Cities)
            .HasForeignKey(d => d.CountryId);

    }

その後、移行コマンド「add-migration initial -ignorechanges」と「update-database -verbose」を実行しましたが、既存のデータベースでは何も起こりません。それで、私は何かを逃しましたか?どうもありがとうございます。

4

0 に答える 0