Using below code,
public class UserProfile
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
// more properties here
}
I thought EF is using newguid(), but when I check database, I see the default value is newsequentialid()
Is this the default behavior of EF? Or it is because I'm using SQL Server 2017?
You're right, by the default newsequentialid()
is used as a default value for GUID properties. newsequentialid()
is recommended over newid()
mostly because of performance considerations.
If you want to have newid()
as default value you could achieve this by enabling migrations and specifying defaultValueSql
in CreateTable()
:
CreateTable(
"dbo.UserProfiles",
c => new
{
Id = c.Guid(nullable: false, identity: true, defaultValueSql: "newid()"),
Name = c.String(),
})
.PrimaryKey(t => t.Id);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With