Is there a way to write a base entity, where the primary key's type is not specified using generics?
For instance, I have been doing this so far:
public class BaseUniqueEntity<T> where T : IComparable, IComparable<T> {
[Key]
public T Key{ get; set; }
}
This was good at the time, but now is giving me design problems. For example, when coding a generic repository I am obligued to specify two type constraints:
public interface IRepository<K, E>
where K : IComparable, IComparable<K>
where E : BaseUniqueEntity<K>
I would only want to specify the entity's type E, but I need the K type for specifying the where E : BaseUniqueEntity<K> constraint.
I can't make Key of type object, because it messes up when creating my tables for me.
So I was think of removing generics from BaseUniqueEntity. Is there a way to accomplish this? I'm out of ideas and I'm pretty new to Entity Framework.
int,Guid,string, whatever. But then all your entities will have to have primary key typed as that.