1

When the user closes the editing window for a single entity object he is asked whether he wants to save the changes he made.

In case of 'yes' I call

DataContext.SaveChanges()

In case of 'no' I set

DataContext.Entry(myObject).State = EntityState.Unchanged

Is the latter enough or can it lead to a big screwup since the changed values of myObject are still changed somewhere in the background?

  • Check out this post: https://stackoverflow.com/questions/28479933/ – abydal Aug 04 '17 at 08:59
  • Maybe it matters that I use WPF (TextBox, DatePicker, etc) and Bindings on the DependencyProperties. But when I open an entry editing window, change some values, close it without saving (via setting .State = EntityState.Unchanged) and reopen it again the old values are in there not the edited ones. How does that fit together with the link you provided me? –  Aug 04 '17 at 09:13
  • I assume, that you are using entity framework model to bind controls - is that correct? This is not good idea to allow your domain model be used on "frontend" page. You should use simple DTO, and pass those values to service layer. – Piotr Aug 04 '17 at 09:35
  • @Piotr I don't fully get the question. I bind to properties of the objects in the Entity Framework data model (.edmx). For me to clear things can you link to a simple example where DTO is used? –  Aug 04 '17 at 09:50
  • Here is SOF with DTO description : https://stackoverflow.com/questions/1051182/what-is-data-transfer-object – Piotr Aug 04 '17 at 09:56
  • Understood. Well I register a normal DependencyProperty in all editing windows. I thought this would be a best practice with WPF and Entity Framework... However the confusion of my original comment on this question still stands... –  Aug 04 '17 at 10:04

0 Answers0