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 14:19:42
 
 
À
27/06/2014 14:09:58
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:
01602722
Vues:
55
>>>Your query should look something like this:
>>>
>>>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.

This is the GenericRepository class, which is the base class for DeliveryHistoryRepository:
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?
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