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