Entity framework 4 实体框架4.1-如何更新、插入和删除派生类中的数据

Entity framework 4 实体框架4.1-如何更新、插入和删除派生类中的数据,entity-framework-4,entity-framework-4.1,Entity Framework 4,Entity Framework 4.1,我有一个名为UserProfile的类,它派生自一个名为User的对象 如何从用户配置文件中插入、更新或删除数据?您将在上下文中定义DbSet。您可以定义一组基本用户类型,它将能够使用用户和所有派生实体类型 public class Context : DbContext { public DbSet<User> Users { get; set; } } 修改: var profile = GetSomeProfile(); context.Entry(profile)

我有一个名为UserProfile的类,它派生自一个名为User的对象


如何从用户配置文件中插入、更新或删除数据?

您将在上下文中定义
DbSet
。您可以定义一组基本
用户
类型,它将能够使用
用户
和所有派生实体类型

public class Context : DbContext
{
     public DbSet<User> Users { get; set; }
}
修改:

var profile = GetSomeProfile();
context.Entry(profile).State = EntityState.Modified;
删除:

var anotherProfiele = GetSomeOtherProfile();
context.Users.Remove(anotherProfile);
在EF5中,在类似的情况下(基类
Supplier
DbSet
,派生类
SupplierViewModel
),我得到
InvalidOperationException
,消息为“{”映射,无法找到EntityType“ViewModelLayer.ViewModels.SupplierViewModel.”的元数据信息。为什么?
var anotherProfiele = GetSomeOtherProfile();
context.Users.Remove(anotherProfile);