我有两个模型类:
请求:
public partial class Request
{
public long Id { get; set; }
public string Username { get; set; }
public string Description { get; set; }
public System.DateTime CreateDate { get; set; }
public long DeviceId { get; set; }
public bool IsFinalized { get; set; }
public Nullable<long> ParentId { get; set; }
public virtual Device Device { get; set; }
}
设备:
public partial class Device
{
public Device()
{
this.Requests = new List<Request>();
}
public long Id { get; set; }
public string Serial { get; set; }
public string AssetNumber { get; set; }
public System.DateTime CreatedDate { get; set; }
public virtual ICollection<Request> Requests { get; set; }
}
我必须更新我使用此方法的模型
public void Update(RequestViewModel viewModel)
{
var entity = _mappingEngine.Map<Request>(viewModel);
_requests.Attach(entity);
_uow.Entry(entity).State = EntityState.Modified;
}
但调用Request
方法后只更新Update
模型。我想更新两个模型。请帮帮我。
答案 0 :(得分:0)
将实体附加到DbContext
,标记附加实体及其所有依赖项(即关联实体)UnChanged
。所以你必须告诉EF
哪些实体是新的以及哪些实体被修改。