C# 更新实体框架TPH中的子属性
我不熟悉C#/MVC中的EF继承,我正在尝试更新子类的导航属性,但不知道如何更新。显然,子类继承自父类,并且指定了自己的EF映射。我必须使用父类型更新数据库,否则不会将任何内容推送到数据库(不过不会抛出错误)。但是,使用父类不会公开子属性,因此我无法更新它们,甚至无法将其推送到DB 在EF中处理子类特定属性的正确方法是什么 这是一个一般性的问题,而不是针对我的问题,但这里的代码不起作用C# 更新实体框架TPH中的子属性,c#,asp.net-mvc,entity-framework,C#,Asp.net Mvc,Entity Framework,我不熟悉C#/MVC中的EF继承,我正在尝试更新子类的导航属性,但不知道如何更新。显然,子类继承自父类,并且指定了自己的EF映射。我必须使用父类型更新数据库,否则不会将任何内容推送到数据库(不过不会抛出错误)。但是,使用父类不会公开子属性,因此我无法更新它们,甚至无法将其推送到DB 在EF中处理子类特定属性的正确方法是什么 这是一个一般性的问题,而不是针对我的问题,但这里的代码不起作用 // get the existing task using the model posted from vi
// get the existing task using the model posted from view,
// convert it to child class (GetTaskById returns parent class)
PETask task = _projectService.GetTaskById(model.Id).ConvertToET();
var proj = _projectService.GetById(model.ProjectId);
// error checking
if (ModelState.IsValid)
{
// use AutoMapper to convert the posted data to entity, passing task as
// a parameter to preserve proxies
task = model.ToEntity(task);
if (model.SOId.HasValue)
{
SalesOrder so = _salesOrderService.GetByOrderId(model.SOId.Value);
task.SalesOrderId = so.Id;
task.SalesOrder = so;
}
_projectService.Update(task);
// all information is correct, including a proxy for the SalesOrder property
// and the actual SalesOrderId, but the DB is not updated. no error is thrown.
}
请显示您当前的代码结构和您目前的代码结构。@Developer我已将其添加到OP中。