2

行ごとに一意のハッシュ値が必要なので、 type の列を作成しましたGuid

public class SendingLog
{
    [Key]
    public int SendingLogId { get; set; }

    [Required, ForeignKey("Apartment")]
    public int ApartmentId { get; set; }

    public virtual Apartment Apartment { get; set; }

    Guid RowGuid { set; get; }

    [MaxLength(256), Required]
    public string Email { get; set; }

    [Required]
    public DateTime SentTime { get; set; }

    public int SentByUserId { get; set; }
}

ただし、コードの最初の移行では、次のコードが生成されました。

public override void Up()
{
    CreateTable(
        "dbo.SendingLogs",
        c => new
            {
                SendingLogId = c.Int(nullable: false, identity: true),
                ApartmentId = c.Int(nullable: false),
                Email = c.String(nullable: false, maxLength: 256),
                SentTime = c.DateTime(nullable: false),
                SentByUserId = c.Int(nullable: false),
            })
        .PrimaryKey(t => t.SendingLogId)
        .ForeignKey("dbo.Apartments", t => t.ApartmentId, cascadeDelete: true)
        .Index(t => t.ApartmentId);
}

Guid列が削除された理由

4

1 に答える 1

4

スコープが だからですprivate

先頭の を省略することpublicで、コード ファースト マイグレーション ジェネレーターはそれを気にする必要があるプロパティと見なしません。

次のように変更します。

public Guid RowGuid { set; get; }
于 2013-02-11T05:27:42.123 に答える