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

编程入门 行业动态 更新时间:2024-10-09 12:34:48
本文介绍了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() 函数

本文发布于:2023-11-15 06:27:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1591959.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   DbSet   EF   lt   Load

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!