You should only set a property of a temporal type (like DateTime or DateTimeOffset) as the primary key of a table if the
values are guaranteed to be unique.
Using temporal types as the primary key of a table is risky. When these types are used as primary keys, it usually means that each new key is
created with the use of .Now or .UtcNow properties from DateTime and DateTimeOffset classes. In
those cases, duplicate keys exceptions may occur in many ways:
DateTime type); The rule raises an issue if:
Id, <type name>Id or decorated by the [Key] or
[PrimaryKey] attribute. Either use a GUID or the auto generated ID as a primary key.
internal class Account
{
public DateTime Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
}
internal class Account
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
}
or
internal class Person
{
[Key]
public DateTime PersonIdentifier { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
}
internal class Person
{
[Key]
public Guid PersonIdentifier { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
}