>>>public IQueryable< DeliveryHistory> GetByRouteId(Guid id) >>>{ >>>return context.DeliveryHistories // The context property that controls access to our data >>>.Where(dh => dh.RunSheetDetail.RunSheetHeader.rnh_rtefk == id) // Filter the data by the routes >>>.Select(dh => new DeliveryHistorySimple() // Select a subset of the data. If you want all of the DeliveryHistory entity, get rid of the select function >>>{ >>> del_pk = dh.del_pk, >>> del_time = dh.del_time, >>> }); >>>} >>>>context in my example should be an instance of your DataContext class. Your DeliveryHistoryRepository class takes it in as a parameter in the constructor, but without knowing the base class, I don't know what property it saves it under.
using System; using System.Data; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Linq; namespace IBCPackTrack.Data { public class GenericRepository<T> : IRepository<T> where T : class { protected DbSet<T> DBSet { get; set; } protected DbContext Context { get; set; } public GenericRepository(DbContext context) { if (context == null) { throw new ArgumentException("An instance of DbContext is " + "required to use this repository.", "context"); } this.Context = context; this.DBSet = this.Context.Set<T>(); } public virtual IQueryable<T> GetAll() { return this.DBSet; } public virtual T GetById(Guid id) { return this.DBSet.Find(id); } public virtual void Add(T entity) { DbEntityEntry entry = this.Context.Entry(entity); if (entry.State != EntityState.Detached) { entry.State = EntityState.Added; } else { this.DBSet.Add(entity); } } public virtual void Update(T entity) { DbEntityEntry entry = this.Context.Entry(entity); if (entry.State == EntityState.Detached) { this.DBSet.Attach(entity); } entry.State = EntityState.Modified; } public virtual void Detach(T entity) { DbEntityEntry entry = this.Context.Entry(entity); entry.State = EntityState.Detached; } public virtual void Delete(T entity) { DbEntityEntry entry = this.Context.Entry(entity); if (entry.State != EntityState.Deleted) { entry.State = EntityState.Deleted; } else { this.DBSet.Attach(entity); this.DBSet.Remove(entity); } } public virtual void Delete(Guid id) { var entity = this.GetById(id); if (entity != null) { this.Delete(entity); } } } }Does that show you what it should be?