Entity framework core 在EF Core Cosmos中生成默认值

Entity framework core 在EF Core Cosmos中生成默认值,entity-framework-core,azure-cosmosdb,Entity Framework Core,Azure Cosmosdb,在我的Cosmos数据库中,我有一个属性CreatedAt,它是一个DateTime。我希望在插入时自动生成值 在我的OnModelCreating方法中,我尝试了以下方法,但没有成功: modelBuilder.Entity().Property(p=>p.CreatedAt.ValueGeneratedOnAdd() modelBuilder.Entity().Property(p=>p.CreatedAt).HasDefaultValueSql(“getdate()”) modelBui

在我的Cosmos数据库中,我有一个属性
CreatedAt
,它是一个
DateTime
。我希望在插入时自动生成值

在我的
OnModelCreating
方法中,我尝试了以下方法,但没有成功:

  • modelBuilder.Entity().Property(p=>p.CreatedAt.ValueGeneratedOnAdd()
  • modelBuilder.Entity().Property(p=>p.CreatedAt).HasDefaultValueSql(“getdate()”)
  • modelBuilder.Entity().Property(p=>p.CreatedAt).hasdaultvalue(DateTime.Now)

在Cosmos DB Emulator中,此属性始终设置为默认的日期时间值。我做错了什么?

你有什么收获吗?对于
int
属性,我也看到了同样的情况-它失败了,因为没有设置值。只有通过使用DbContext中的ChangeTracker并枚举AddIdentity和UpdateData,才能对CreatedAt和UpdatedAt执行此操作。您有何收获?对于
int
属性,我也看到了同样的情况-它失败了,因为没有设置值。仅针对CreatedAt和UpdatedAt,使用DbContext中的ChangeTracker并枚举AddIdentity和UpdateData