DbSetlt;entitygt;.Load() function missing in EF 6.0(EF 6.0 中缺少 DbSetentity.Load() 函数)
问题描述
我正在尝试访问 DbSet
函数来加载实体.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() 函数


- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01