Lets say we have a simple DTO with properties Id, Name. If this DTO comes from database through some data layer, Id should be of type int. If this DTO comes from Active Directory, through some data layer, Id should be of type Guid.
What would be the best way to implement this?
The easiest way is to simply have two properties each of their appropriate type:
public Guid ActiveDirectoryID {get;set;};public int DatabaseID {get;set;};As an alternative you can define the
IDproperty as an Object and implement it with an overloadedGetID()andSetID()for both types.It’s possible but not trivial to convert between a Guid and Int types.