繁体   English   中英

为什么要删除Guid列?

[英]Why was Guid column removed?

我需要为每一行提供唯一的哈希值,因此我创建了一个类型为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列被删除?

这是因为它的作用域是private

通过省略前面的public ,代码优先迁移生成器不会将其视为需要担心的属性。

更改为:

public Guid RowGuid { set; get; }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM