gpt4 book ai didi

c# - 使用 Entity Framework 创建新记录

转载 作者:太空狗 更新时间:2023-10-30 00:08:03 25 4
gpt4 key购买 nike

我有一个表,其主键 id 是一个标识列。我认为当创建一条新记录时,id 将递增 1。

但是调试的时候发现是0。为什么?

必要的代码:

  public DbSet<testDetails> testDetailRecords { get; set; }
testDetails test = testContext.testDetailRecords.Create();
// test.id is 0 when hover over it
public class testDetails : IEntityWithRelationships
{
[Key]
[Required]
[Display(Name = "Primary Key", Description = "Primary Key")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long id { get; set; }

最佳答案

在您使用 SaveChanges() 提交记录之前,不会创建该记录。

关于c# - 使用 Entity Framework 创建新记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13401297/

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