DDD and Entity Base, Model using multiple identity types
Posted
by Thomas
on Stack Overflow
See other posts from Stack Overflow
or by Thomas
Published on 2010-05-03T14:39:54Z
Indexed on
2010/05/03
14:48 UTC
Read the original article
Hit count: 269
ddd
I have a model that looks like this:
public interface IEntity
{
int Id { get; set; }
}
Then the idea is to have my entities inherit from this interface:
public class User : IEntity
{
public int Id { get; set; }
}
However, one of my entities actually has a Guid as an identifier.
public class UserSession
{
public Guid Id { get; set; }
}
I really would like all my entities inheriting from the same interface but that would force me to add an integer based identity column to the UserSession which is unnecessary since Guid is the identity, but it would keep the domain model nice since all entities would inherit from the same base.
What options do I have in this scenario? Can I have two base interfaces, one for int and one for Guid? Should I add an identity column into the UserSession entity although it is unnecessary? I need the Guid so I can't just get rid of it and replace it with and integer.
Any thoughts on best practices?
© Stack Overflow or respective owner