【发布时间】:2015-09-03 13:13:52
【问题描述】:
我的实体如下所示:
public class AddPatientReportDentalChartInput : IInputDto
{
[Required]
[MaxLength(PatientReportDentalChart.TeethDesc)]
public string Image { get; set; }
[Required]
public virtual int PatientID { get; set; }
[Required]
public virtual int TeethNO { get; set; }
public string SurfaceDefault1 { get; set; }
public string SurfaceDefault2 { get; set; }
public string SurfaceDefault3 { get; set; }
public string SurfaceDefault4 { get; set; }
public string SurfaceDefault5 { get; set; }
}
我要更新的方法是:
public async Task addPatientReportDentalChart(AddPatientReportDentalChartInput input)
{
var pid = input.PatientID;
var chartdetails = _chartReportRepository
.GetAll()
.WhereIf(!(pid.Equals(0)),
p => p.PatientID.Equals(pid)).ToList();
if (chartdetails.Count>0)
{
//Update should be apply here
//please suggest me the solution using updatesync
}
else
{
var patientinfo = input.MapTo<PatientReportDentalChart>();
await _chartReportRepository.InsertAsync(patientinfo);
}
}
当我想更新现有实体时,InsertAsync 的等价物是什么?有没有UpdateAsync 等效的方法?
【问题讨论】:
-
我只想使用 updateSync 方法更新数据库,例如 Inserting await _chartReportRepository.InsertAsync(patientinfo);
-
使用
FindAsync查找实体,修改它,然后使用SaveChangesAsync。 -
你能推荐我上面的代码吗?
-
在下面查看我的答案。
标签: c# entity-framework asp.net-mvc-4 entity-framework-5 entity-framework-6