Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
'System.Data.Entity.DbSet' does not contain a definition
Message
De
27/06/2014 15:53:15
 
 
À
27/06/2014 14:48:03
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Versions des environnements
Environment:
C# 4.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01602673
Message ID:
01602746
Vues:
70
>I gave you a bad suggestion. The Context property in your GenericRepository is the base DbContext class, which doesn't have DeliveryHistories. DBSet would probably be better to use. If you want to use the context, you will either need to change the type on the property or cast it to your Data_Context class.

OK, so just:
return DBSet.Where(dh => dh.RunSheetDetail.RunSheetHeader.rnh_rtefk == id);
compiles successfully, thanks.

However, I get an error in my DeliveryHistoriesController where I try to call this new method:
        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");
        }
The error is:
'IBCPackTrack.Data.IRepository<IBCPackTrack.Models.DeliveryHistory>' does not contain a definition for 'GetByRouteId' and no extension method 'GetByRouteId' accepting a first argument of type 'IBCPackTrack.Data.IRepository<IBCPackTrack.Models.DeliveryHistory>' could be found (are you missing a using directive or an assembly reference?)
I guess this has something to do with my ApplicationUnit definition:
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;
            }
        }

    }
}
My IRepository is defined like this:
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);
    }
}
I guess I need to do some special kind of repository for my DeliveryHistories, is that right?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform