I am trying to implement a generic GetById(T id) method which will cater for types which may have differing ID types. In my example, I have an entity which has
To your question:
I am trying to implement a generic GetById(T id) method which will cater for types which may have differing ID types. In my example, I have an entity which has an ID of type int, and one of type string.
public virtual TEntity GetById(TId id)
{
return context.Set().SingleOrDefault(x => x.Id == id);
}
For generic parameter, just make a generic method like above