EF 6.0 中缺少 DbSet<entity>.Load() 函数

DbSetlt;entitygt;.Load() function missing in EF 6.0(EF 6.0 中缺少 DbSetentity.Load() 函数)

本文介绍了EF 6.0 中缺少 DbSet<entity>.Load() 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问 DbSet.Load() 函数来加载实体.EF 6.0 中不再存在此功能;经过某些调查,我发现它是 EF 扩展库中定义的扩展方法的一部分.

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.

我获得了 EF 6.0 扩展库的参考 NuGet 包,但似乎不再受支持.我试图通过调用 .ToList() 来替代该函数,但是这个方法在处理时返回了一个内部异常:

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:

({"列名无效.[节点名(如果有)=Extent1,列名=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;
        }
    }
}

另外请哪位指出ToList()Load()的区别?

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

推荐答案

发现需要补充:

using System.Data.Entity;

这篇关于EF 6.0 中缺少 DbSet<entity>.Load() 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:EF 6.0 中缺少 DbSet<entity>.Load() 函数

基础教程推荐