我正在尝试访问 DbSet<EntityClass>.Load()
加载实体的函数。 EF 6.0 中不再存在此功能;经过一定的调查,我发现它是 EF 扩展库中定义的扩展方法的一部分。
我获得了 EF 6.0 扩展库的引用 NuGet 包,但它似乎不再受支持。我试图通过调用 .ToList()
来替代该功能,但是这个方法在处理后返回给我一个内部异常:
({"The column name is not valid. [ Node name (if any) = Extent1,Column name = HasErrors ]"} )
我根据数据库表仔细检查了映射类,但看起来不错。不知道我错过了什么。下面是我的映射类的代码:
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");
}
}
下面是对数据库的实际调用:
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()
?
最佳答案
我发现我需要添加:
using System.Data.Entity;
关于c# - EF 6.0 中缺少 DbSet<entity>.Load() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19605682/