DBContext로 변경 사항을 탐지합니다
-
21-12-2019 - |
문제
SaveChanges 메소드를 실제로 적용하기 전에 변경 사항이 탐지되지 않은 이유를 이해하지 못하고 있습니다.나는 단지 일을 테스트하고 있습니다.다음은 코드입니다.
Lodging query = context.Lodgings.SingleOrDefault(d => d.LodgingName == "Hotel4");
context.Entry(query).Reference(l=>l.Destination).Load();
Console.WriteLine(query.Destination.DestinationName);
query.Destination.DestinationName = "Some Where Else";
Console.WriteLine(context.Entry(query).State);
Console.WriteLine(query.Destination.DestinationName);
context.ChangeTracker.DetectChanges();
Console.WriteLine(context.Entry(query).State);
Console.WriteLine(query.Destination.DestinationName);
.
출력은 "변경되지 않음"입니다.물론 변경 사항을 저장하면 데이터베이스가 업데이트됩니다.
다른 팁
Your question doesnt explain about actual requirement.May be you will find the answer here.
제휴하지 않습니다 StackOverflow