Find an entity using its Unique Key
-
24-06-2021 - |
Question
In my asp.net mvc 3 application, I have a generic Repository. I use the Find method of the DbSet class to find an entity by its Primary Key, like here:
private DbSet<T> _dbSet;
public T FindByID(object id)
{
return _dbSet.Find(id);
}
Is there any way I can find the entity using the Unique Key as well? I was not able to find the source code for the DbSet class. I would like to extend the DbSet class and add a new method to it for this purpose, if it's possible.
Solution
It seems like Entity Framework does not support unique keys, according to this answer:
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow