protected PropertyInfo GetProperty(TEntity entity) where TEntity : EntityObject { return GetProperty(entity, entity.EntityKey.EntityKeyValues[0].Key); } public bool PropertyEquals(TEntity entity, string value) where TEntity : EntityObject { var prop = GetProperty(entity); if (prop.GetValue(entity, null).ToString() == value) { return true; } else { return false; } } public class TempRepo : RepositoryBase { } public TEntity GetEntity(Func whereClause, string id) where TEntity : EntityObject { //Check to see if we have a null function, if so, dont run one var runWhereClause = true; if (whereClause == default(Func)) runWhereClause = false; //Get all the types from the object context //if the property type is the one we're looking for //use a LINQ query to find it var result = new List(); var newRepo = new TempRepo(); var properties = newRepo.UoW.ObjectContext.GetType().GetProperties().ToList(); foreach (PropertyInfo prop in properties) { if (prop.PropertyType.FullName.Contains(typeof(ObjectSet).FullName)) { if (runWhereClause) result.AddRange((from i in ((IEnumerable)prop.GetValue(newRepo.UoW.ObjectContext, null)).ToList() where PropertyEquals(i, id) select i).ToList()); } } return result.First(); }