سؤال

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.

هل كانت مفيدة؟

المحلول

It seems like Entity Framework does not support unique keys, according to this answer:

Alternate/candidate key in ADO.NET data model

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top