0

Is it possible to use phantom types with Code First for my primary key?

I have something like this:

class Id<TEntity, TKey>
   where TEntity : Entity
{
   // implementation
}

class Entity<TEntity, TKey> {
   [Key]
   public Id<MyEntity, Guid> Id { get; set; }
}

class MyEntity : Entity<MyEntity, Guid> {

}
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445

1 Answers1

2

No. EF has a predefined set of allowed data types for properties. And it only knows how to convert these types to database types and back. There is not mechanism to implement custom type converters either in EF. nHibernate may allow this.

Eranga
  • 32,181
  • 5
  • 97
  • 96