Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DbSet<entity>.Load() function missing in EF 6.0

I am trying to access the DbSet<EntityClass>.Load() function to load the entities. This function no longer exists in EF 6.0; upon certain investigation I found that it is a part of the extension methods defined in the EF extension library.

I get the reference NuGet Packages for EF 6.0 extended library but seems like it's no longer supported. I tried to do an alternative of that function by calling .ToList(), but this method upon processing returns me an inner exception:

({"The column name is not valid. [ Node name (if any) = Extent1,Column name = HasErrors ]"} )

I double checked the mapping class against the database table, but it looks fine. Not sure what I am missing. Below is the code of my mapping class:

internal class CustomerMapping : EntityTypeConfiguration<Customer>
{
    public CustomerMapping()
    {
        this.HasKey(t => t.Id);

        this.Property(t => t.Id).HasColumnName("CUSTOMER_ID");
        this.Property(t => t.Name).HasMaxLength(30).HasColumnName("NAME");
        this.Property(t => t.Email).HasMaxLength(30).HasColumnName("EMAIL");
        this.Property(t => t.PhoneNo).HasMaxLength(100).HasColumnName("PHONE_NO");
        this.Property(t => t.MobileNo).HasMaxLength(100).HasColumnName("MOBILE_NO");
        this.Property(t => t.Address1).HasMaxLength(100).HasColumnName("ADDRESS1");
        this.Property(t => t.Address2).HasMaxLength(100).HasColumnName("ADDRESS2");
        this.Property(t => t.CustomerType).HasMaxLength(100).HasColumnName("CUSTOMER_TYPE");
        this.Property(t => t.Notes).HasMaxLength(100).HasColumnName("NOTES");

        this.ToTable("CUSTOMERS");
    }
}

Below is the actual call made to the database:

internal class EntityService : IEntityService
{
    private ObservableCollection<Customer> customers;


    public DBContextManager DataBaseContext { get; set; }

    public ObservableCollection<Customer> Customers
    {
        get
        {
            if (customers == null && DataBaseContext != null)
            {
               // DataBaseContext.Set<Customer>().Load()
                DataBaseContext.Set<Customer>().ToList();
                customers = DataBaseContext.Set<Customer>().Local;

            }
            return customers;
        }
    }
}

Also please can any one point out the difference between ToList() and Load()?

like image 696
Hassan Akhtar Avatar asked Oct 26 '13 10:10

Hassan Akhtar


People also ask

How you can load related entities in EF?

Entity Framework supports three ways to load related data - eager loading, lazy loading and explicit loading. The techniques shown in this topic apply equally to models created with Code First and the EF Designer.

Is DbSet part of DbContext?

Definition. A DbSet represents the collection of all entities in the context, or that can be queried from the database, of a given type. DbSet objects are created from a DbContext using the DbContext.

What is the difference between DbSet and DbContext?

Intuitively, a DbContext corresponds to your database (or a collection of tables and views in your database) whereas a DbSet corresponds to a table or view in your database.

What is DbSet in Entity Framework Core?

In Entity Framework Core, the DbSet represents the set of entities. In a database, a group of similar entities is called an Entity Set. The DbSet enables the user to perform various operations like add, remove, update, etc. on the entity set.


Video Answer


2 Answers

I found I needed to add:

using System.Data.Entity;
like image 171
Paul Cookson Avatar answered Oct 08 '22 14:10

Paul Cookson


Also, besides System.Data.Entity, you must add the System.Linq namespace as well as System.Windows.

like image 5
StephenDonaldHuffPhD Avatar answered Oct 08 '22 12:10

StephenDonaldHuffPhD