return DBSet.Where(dh => dh.RunSheetDetail.RunSheetHeader.rnh_rtefk == id);>>
public ActionResult Get(Guid id) >> { >> DeliveryHistoryViewModel vm = new DeliveryHistoryViewModel(); >> >> vm.DeliveryHistory = this._unit.DeliveryHistories.GetByRouteId(id); // error is here >> >> if (vm.DeliveryHistory != null) >> { >> return View("DeliveryHistory", vm); >> } >> >> return View("NotFound"); >> }>>
using System; >>using IBCPackTrack.Models; >> >>namespace IBCPackTrack.Data >>{ >> public class ApplicationUnit : IDisposable >> { >> private DataContext _context = new DataContext(); >> >> private IRepository<AirWayBill> _airwaybills = null; >> private IRepository<Customer> _customers = null; >> private IRepository<DeliveryHistory> _deliveryhistories = null; >> private IRepository<DispositionCode> _dispositioncodes = null; >> private IRepository<Route> _routes = null; >> private IRepository<RunSheetDetail> _runsheetdetails = null; >> private IRepository<RunSheetHeader> _runsheetheaders = null; >> private IRepository<ScanCode> _scancodes = null; >> >>// code removed for this posting >> >> public IRepository<DeliveryHistory> DeliveryHistories >> { >> get >> { >> if (this._deliveryhistories == null) >> { >> this._deliveryhistories = new GenericRepository<DeliveryHistory>(this._context); >> } >> return this._deliveryhistories; >> } >> } >> >> } >>}>>
using System; >>using System.Linq; >> >>namespace IBCPackTrack.Data >>{ >> public interface IRepository<T> where T : class >> { >> IQueryable<T> GetAll(); >> T GetById(Guid id); >> void Add(T entity); >> void Update(T entity); >> void Delete(T entity); >> void Delete(Guid id); >> void Detach(T entity); >> } >>}>>
>using System; >using System.Linq; > >namespace IBCPackTrack.Data >{ > public interface IRouteBasedRepository< T> : IRepository< T> where T : class > { > IQueryable< T> GetByRouteId(Guid id); > } >}>
public class ApplicationUnit : IDisposable { private DataContext _context = new DataContext(); private IRepository<DeliveryHistory> _deliveryhistories = null;to this:
public class ApplicationUnit : IDisposable { private DataContext _context = new DataContext(); private DeliveryHistoryRepository _deliveryhistories = null;Is that right?
"Cannot implicitly convert type 'System.Linq.IQueryable<IBCPackTrack.Models.DeliveryHistory>' to 'IBCPackTrack.Models.DeliveryHistory'. An explicit conversion exists (are you missing a cast?)"
This is the code:[ActionName("Edit")] public ActionResult Get(Guid id) { DeliveryHistoryViewModel vm = new DeliveryHistoryViewModel(); vm.DeliveryHistory = this._unit.DeliveryHistories.GetByRouteId(id); if (vm.DeliveryHistory != null) { return View("DeliveryHistory", vm); } return View("NotFound"); }Which I can get around using:
vm.DeliveryHistory = (DeliveryHistory)this._unit.DeliveryHistories.GetByRouteId(id);
Am I doing this correctly?