lundi 22 avril 2019

Entity Framework Core use Guid as PK

Should I use Guid as PK in every table?

I'm not experienced in using EF Core or EF. Most of the time when searching for patterns I can find something like this

public class BaseEntity
{
    public Guid Id { get; private set; }
    public DateTime CreatedAt { get; private set; }
    public DateTime ModifiedAt { get; private set; }

    public EntityBase()
    {
        Id = Guid.NewGuid();
        CreatedAt = DateTime.UtcNow;
        ModifiedAt = DateTime.UtcNow;
    }
}

where Guid is used as PK and other entities extend this base class. That should be well known pattern.

But what I'm wondering is if it's good idea to use Guid instead of long or int in every table as PK and if does, should I use Guid also as Foreign Key or should?

Another question in case that above question is true is if in many-to-many relation, joining entity should extend the base entity.

Please, feel free to correct my question grammatically.

Aucun commentaire:

Enregistrer un commentaire