Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected PropertyInfo GetProperty<TEntity>(TEntity entity) where TEntity : EntityObject
- {
- return GetProperty<TEntity>(entity, entity.EntityKey.EntityKeyValues[0].Key);
- }
- public bool PropertyEquals<TEntity>(TEntity entity, string value) where TEntity : EntityObject
- {
- var prop = GetProperty<TEntity>(entity);
- if (prop.GetValue(entity, null).ToString() == value)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public class TempRepo : RepositoryBase<myEntityFrameWorkObject>
- {
- }
- public TEntity GetEntity<TEntity>(Func<TEntity, string, bool> 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<TEntity, string, bool>))
- 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<TEntity>();
- var newRepo = new TempRepo();
- var properties = newRepo.UoW.ObjectContext.GetType().GetProperties().ToList();
- foreach (PropertyInfo prop in properties)
- {
- if (prop.PropertyType.FullName.Contains(typeof(ObjectSet<TEntity>).FullName))
- {
- if (runWhereClause)
- result.AddRange((from i in
- ((IEnumerable<TEntity>)prop.GetValue(newRepo.UoW.ObjectContext, null)).ToList()
- where PropertyEquals(i, id)
- select i).ToList());
- }
- }
- return result.First();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement