我试图访问 DbSet< EntityClass> .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.
我得到的引用的NuGet包为EF 6.0扩展库,但好像它不再支持。我试图通过调用做到这一点功能的替代 .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]})
我仔细检查了映射类对数据库中的表,但它看起来不错。不知道我错过了什么。下面是我的映射类的code:
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()
和加载()
?
我发现我需要添加:
using System.Data.Entity;