---
# System prepended metadata

title: EF CodeFirst Guid
tags: [火箭]

---

# EF CodeFirst Guid 
###### tags: `火箭`

在add migration 時 增加defaultValueSql: "newId()" 參數

defaultValueSql: "GETDATE()" 增加當下時間

https://magnussundstrom.se/blog/add-guid-ef-code-first
https://iter01.com/422164.html
```csharp=
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid UniqueId { get; set; }

protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.AddColumn<Guid>(
    name: "UniqueId",
    table: "Orders",
    nullable: false,
    defaultValueSql: "newId()");
} 
```

