configuration.CreateMap<TpmProject, TpmProjectEditDto>();
configuration.CreateMap<TpmProjectEditDto, TpmProject>();
configuration.CreateMap<TpmProjectClassLink, TpmProjectClassLinkDto>();
configuration.CreateMap<TpmProjectClassLinkDto, TpmProjectClassLink>();
configuration.CreateMap<TpmProjectContactLink, TpmProjectContactLinkDto>();
configuration.CreateMap<TpmProjectContactLinkDto, TpmProjectContactLink>();
public partial class TpmProject : FullAuditedEntity<long, User>
{
public string Name { get; set; }
public virtual ICollection<TpmProjectContactLink> TpmProjectContactLink { get; set; }
public virtual ICollection<TpmProjectClassLink> TpmProjectClassLink { get; set; }
}
public class TpmProjectEditDto : : FullAuditedEntity<long?, User>
{
public string Name { get; set; }
public ICollection<TpmProjectContactLinkDto> TpmProjectContactLink { get; set; }
public ICollection<TpmProjectClassLinkDto> TpmProjectClassLink { get; set; }
}
}
public class TpmProjectClassLink: FullAuditedEntity<long, User>
{
public string baseClassNo { get; set; }
public string name { get; set; }
public virtual long? TpmProjectId { get; set; }
[ForeignKey("TpmProjectId")]
public virtual TpmProject TpmProject { get; set; }
}
public class TpmProjectClassLinkDto : FullAuditedEntity<long, User>
{
public string baseClassNo { get; set; }
public string name { get; set; }
public virtual long? TpmProjectId { get; set; }
}
public partial class TpmProjectContactLink: FullAuditedEntity<long, User>
{
public string Name { get; set; }
public virtual long? TpmProjectId { get; set; }
[ForeignKey("TpmProjectId")]
public virtual TpmProject TpmProject { get; set; }
}
public partial class TpmProjectContactLinkDto : FullAuditedEntity<long,User>
{
public string Name { get; set; }
public virtual long? TpmProjectId { get; set; }
}
这是更新方法
[UnitOfWork(IsDisabled = true)]
protected virtual async Task Update(TpmProjectEditDto input)
{
var entity = await _entityRepository.GetAllIncluding(t=>t.TpmProjectContactLink,t=>t.TpmProjectClassLink,t => t.TpmProjectErrorLink).Where(t => t.Id == input.Id).SingleOrDefaultAsync();
entity.TpmProjectClassLink.Clear();
entity.TpmProjectContactLink.Clear();
await CurrentUnitOfWork.SaveChangesAsync();
ObjectMapper.Map(input, entity);
await _entityRepository.UpdateAsync(entity);
}
抛出错误
Mvc.ExceptionHandling.AbpExceptionFilter-实体类型的实例 无法跟踪“ TpmProjectContactLink”,因为另一个实例 具有与{'Id'}相同的键值的值已经被跟踪。什么时候 附加现有实体,请确保只有一个具有 附加了给定的键值。考虑使用 'DbContextOptionsBuilder.EnableSensitiveDataLogging'以查看 关键值冲突。 System.InvalidOperationException:实例 类型为“ TpmProjectContactLink”的实体无法跟踪,因为 具有相同的{'Id'}键值的另一个实例已经在 跟踪。连接现有实体时,请确保只有一个实体 具有给定键值的实例被附加。考虑使用 'DbContextOptionsBuilder.EnableSensitiveDataLogging'以查看 冲突的键值。
如何修改我的代码以更新一对多