gpt4 book ai didi

c# - 为什么删除了 Guid 列?

转载 作者:行者123 更新时间:2023-11-30 21:00:38 25 4
gpt4 key购买 nike

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

关于c# - 为什么删除了 Guid 列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14806218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com