How can I get the 1st EntityKey name for an Entity for Entity Framework 4 because I\'m building a repository system and I wanted to get an item by Id (which is the primary key o
public static string GetPrimaryKeyName(this object entity)
{
var prop = entity.GetType().GetProperties().Where(x =>x.GetCustomAttributes(false).Where(y => y is ColumnAttribute&&((ColumnAttribute)y).IsPrimaryKey == true).Any()).FirstOrDefault();
if (prop != null)
return prop.Name;
return string.Empty;
}