Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear friends iam getting the error

'System.Data.Entity.DbSet`1<Northwind.Data.Customer>' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'System.Data.Entity.DbSet`1<Northwind.Data.Customer>'


iam getting the error here, how to solve this error ?

private void GetCustomers()
        {
//error in following line 
            _customers = new NORTHWNDEntities().Customers.ToList();           
            
        }


What I have tried:

full code of the classes
 using Northwind.Data;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
namespace Northwind.ViewModel
{
    public class MainWindowViewModel
    {
        private IList<Customer> _customers;
        
        public IList<Customer> Customers
        {
            get
            {
                if (_customers == null)
                {
                    GetCustomers();                    
                }
                return _customers;
                
            }
        }
        private void GetCustomers()
        {
            _customers = new NORTHWNDEntities().Customers.ToList();           
            
        }
    }
} 


and

namespace Northwind.Data
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;
    using System.Linq;
    public partial class NORTHWNDEntities : DbContext
    {
        public NORTHWNDEntities() : base("name=NORTHWNDEntities"){}    
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();            
        }    
        public virtual DbSet<Customer> Customers { get; set; }
        public virtual DbSet<Employee> Employees { get; set; }
        public virtual DbSet<Order_Detail> Order_Details { get; set; }
        public virtual DbSet<Order> Orders { get; set; }
        public virtual DbSet<Product> Products { get; set; }
    }
}
Posted
Comments
Richard MacCutchan 23-Apr-17 3:25am    
Look at the error message.
srilekhamenon 23-Apr-17 5:10am    
My problem is System.Data.Entity.DbSet is a part of entityframework.dll which i have referenced in data access layer. i do not want to reference this dll in other layers, how can i solve this problem without doing same.
Richard MacCutchan 23-Apr-17 7:24am    
I do not know what you mean. But your problem is clearly stated in the error message; that is what you need to correct.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900