DBContext.Set <T>не содержит определения Set <T> - PullRequest
0 голосов
/ 12 февраля 2012

Я пытаюсь реализовать абстрактный шаблон хранилища, как описано в ЭТОМ посте. Я получаю сообщение об ошибке

«C» не содержит определения «Set» и метода расширения 'Set', принимающий первый аргумент типа 'C', может быть найден (вы отсутствует директива using или ссылка на сборку?)

, где C - DBContext

namespace Rental.Data.Entity.Repository
{
   public abstract class GenericRepo<C, T> : 
       IGenericRepo<T> where T : class where C : RentalContainer, new()
   {
       private C _DBContext = new C();
       protected C DBContext
       {

           get { return _DBContext; }
           set { _DBContext = value; }
       }

       public virtual IQueryable<T> GetAll()
       {       

           IQueryable<T> query = _DBContext.Set<T>(); <-- here is gives the error
           return query;
       }

еще одно обновление

public partial class RentalContainer : ObjectContext
    {
        #region Constructors

        /// <summary>
        /// Initializes a new RentalContainer object using the connection string found in the 'RentalContainer' section of the application configuration file.
        /// </summary>
        public RentalContainer() : base("name=RentalContainer", "RentalContainer")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }

        /// <summary>
        /// Initialize a new RentalContainer object.
        /// </summary>
        public RentalContainer(string connectionString) : base(connectionString, "RentalContainer")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }

Ответы [ 2 ]

3 голосов
/ 12 февраля 2012

ObjectContext не имеет метода Set.Он имеет CreateObjectSet метод

   public abstract class GenericRepo<C, T> : IGenericRepo<T> 
     where T : class 
     where C : RentalContainer, new()
   {
       private C _DBContext = new C();
       protected C DBContext
       {

           get { return _DBContext; }
           set { _DBContext = value; }
       }

       public virtual IQueryable<T> GetAll()
       {       

           IQueryable<T> query = _DBContext.CreateObjectSet<T>();
           return query;
       }
   }
2 голосов
/ 12 февраля 2012

Добавить ссылку на EntityFramework.dll

http://msdn.microsoft.com/en-us/library/gg679544(v=vs.103).aspx

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...