웹 응용 프로그램에서 SQL Server 2012와 함께 EF5를 사용하고 있습니다. 저장 단추는 하위 항목 객체와 함께 주제 객체를 눌렀을 때 우리는 웹 API 컨트롤러에 다시 JSON으로 전송 한 후 하위 항목 노트에 변화를 만들어 우리의 프론트 엔드에서웹 API를 사용하면 개체에서 변경된 내용을 Entity Framework에서 어떻게 인식합니까?
public partial class Topic {
public Topic()
{
this.SubTopics = new List<SubTopic>();
}
public int TopicId { get; set; }
public string Name { get; set; }
public int Number { get; set; }
public virtual ICollection<SubTopic> SubTopics { get; set; }
}
public partial class SubTopic
{
public int SubTopicId { get; set; }
public int TopicId { get; set; }
public string Name { get; set; }
public string Notes { get; set; }
public virtual byte[] Version { get; set; }
public virtual Topic Topic { get; set; }
}
: 나는이 개 수업을 . 무엇이 되돌아 오는 지 확인하면 Notes에 대한 새로운 데이터가 표시됩니다. 매개 변수 토픽을 확인할 때 새로운 Notes 데이터도 볼 수 있습니다.
public HttpResponseMessage PutTopic(int id, Topic topic)
{
_uow.Topics.Update(topic);
_uow.Commit();
}
그러나 SQL 프로파일 러를 검사하면 하위 주제 변경에 아무런 변화가 없습니다. 데이터가 검색되면 이전의 SubTopic 데이터가 반환되고 메모에 대한 편집 내용이 손실됩니다.
이와 같은 웹 업데이트의 경우. EF는 무엇이 변경되었는지를 확인하고 변경 사항을 감지하고 새로운 객체와 비교하여 어떤 점을 비교/비교할 수있는 방법이 있습니까? 하위 토픽을 업데이트 하시겠습니까?
구성 :
DbContext.Configuration.ProxyCreationEnabled = false;
DbContext.Configuration.LazyLoadingEnabled = false;
DbContext.Configuration.ValidateOnSaveEnabled = false;
DbContext.Configuration.ValidateOnSaveEnabled = true;
DbContext.Configuration.AutoDetectChangesEnabled = false;
업데이트 방법는 :
public virtual void Update(T entity)
{
DbEntityEntry dbEntityEntry = DbContext.Entry(entity);
if (dbEntityEntry.State == EntityState.Detached)
{
DbSet.Attach(entity);
}
dbEntityEntry.State = EntityState.Modified;
}
objectContext STE 또는 DBContext 변경 추적 프로그램 API를 권장해야한다면 메소드 콘텐츠 업데이트 –