locked
Cannot resolve symbol set? RRS feed

  • Question

  • User1224379429 posted

    Hi 

    I am developing a project with generic entity framework in vs2010 targeting framework 4. When I build the project am getting the error as Cannot resolve symbol set

    Below is my Repository class. Why this error and how to solve this?

      public abstract class Repository<T> : IGenericRepository<T> where T : EntityBase
        {
            private readonly XEntities _entities = new XEntities();
            public IQueryable<T> GetAll()
            {
                throw new NotImplementedException();
            }
    
            public IQueryable<T> FindBy(System.Linq.Expressions.Expression<Func<T, bool>> predicate)
            {
                IQueryable<T> query = _entities.Set<T>().Where(predicate); // Error in this line
                return query;
            }
    
            public void Add(T entity)
            {
            }
    
            public void Delete(T entity)
            {
            }
    
            public void Edit(T entity)
            {
            }
    
            public void Save()
            {
            }
        }

    Thanks

    Wednesday, November 16, 2016 7:46 AM

All replies

  • User283571144 posted

    Hi Athar Ali Khan,

    Athar Ali Khan

    I am developing a project with generic entity framework in vs2010 targeting framework 4. When I build the project am getting the error as Cannot resolve symbol set

    According to your codes, I have written a test demo on my computer, it works well.

    When I build the project, it doesn't show any error.

    My test environment is VS2015 .Net 4.0, Entity Framework4.3.

    I suggest you could update your entity framework version and test it again.

    Besides, if this not solve your problem, I suggest you could write a little demo and upload it.

    I will download the demo and test it on my computer.

    More details about my test demo, you could refer to follow codes:

    EntityBase:

      class EntityBase
        {
            public int Id { get; set; }
        }

    IGenericRepository:

    interface IGenericRepository<T> where T : EntityBase
        {
             IQueryable<T> GetAll();
    
             IQueryable<T> FindBy(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
        }

    Repository:

      public abstract class Repository<T> : IGenericRepository<T> where T : EntityBase
        {
            private readonly ApplicationDBcontest _entities = new ApplicationDBcontest();
            public IQueryable<T> GetAll()
            {
                throw new NotImplementedException();
            }
    
            public IQueryable<T> FindBy(System.Linq.Expressions.Expression<Func<T, bool>> predicate)
            {
                IQueryable<T> query = _entities.Set<T>().Where(predicate); // Error in this line
                return query;
            }
    
            public void Add(T entity)
            {
            }
    
            public void Delete(T entity)
            {
            }
    
            public void Edit(T entity)
            {
            }
    
            public void Save()
            {
            }
        }

    Best Regards,

    Brando

    Thursday, November 17, 2016 6:04 AM
  • User1224379429 posted

    Hi

    Thanks for your reply. I have added xrate.edmx and changed my repository class as below

     public class Repository<T> : IGenericRepository<T> where T : class 
        {
            private readonly xrateEntities _entities = new xrateEntities(); // My edmx entity
            public List<T> GetAll()
            { // here I want to get all records
    List<T> lst = new List<T>(); return lst; } public void Add(T entity) { // here Insert record
    } public void Delete(T entity) { // here delete record
    } public void Edit(T entity) { // update record
    } public void Save() { // here save record
    } public List<T> Find(Expression<Func<T, bool>> predicate) { // get record by the search function
    List<T> lst = _entities.Set<T>().Where(predicate); return lst; } public void Dispose() { } }

    I installed  Install-Package EntityFramework -Version 4.3.1.

    Now am getting error as below 

    FXRates.EF.Data.xrateEntities' does not contain a definition for 'Set' and no extension method 'Set' accepting a first argument of type 'FXRates.EF.Data.xrateEntities' could be found (are you missing a using directive or an assembly reference?)

    Thursday, November 17, 2016 11:42 AM
  • User283571144 posted
    Hi Athar,
    According to your error message, I suggest you could firstly check the you have generated your EF entity's successfully.
    Then I suggest you could make sure you have use right entity.
    I suggest you should check the xrateEntities's type is dbcontext.
    Besides,if you couldn't solve your problem, I suggest you could upload your project online.
    I will download the project and test it on my computer.
    Best regards,
    Brando
    Sunday, November 20, 2016 5:19 AM
  • User1224379429 posted

    HI

    When I added edmx in vs2010 it added the following 2 files

    1) XRate.edmx 2) XRate.Designer.cs

    But when I added the same edmx in vs2013, it added below 5 files 

    1) XRate.edmx 

    2) XRate.Context.tt

    3) XRate.Designer.cs

    4) XRate.edmx.diagram

    5) XRate.tt

    Why there are more files in vs2013. I have installed same entity framework version in both projects.

    Sunday, November 20, 2016 8:53 AM
  • User283571144 posted

    Hi Athar,

    When I added edmx in vs2010 it added the following 2 files

    As far as I know, after using model first, it will generate five files like you created in VS2013.

    I suggest you could firstly make sure your VS2010 have Nuget Package Manager and update to the newest VS2010 version.

    More details about how to use EF model first Pre-Requisites, I suggest you could refer to follow link:

    https://msdn.microsoft.com/en-gb/data/jj205424(v=vs.113).aspx

    Best Regards,

    Brando

    Sunday, November 20, 2016 12:31 PM