Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. COBut `Attach` and `SaveChanges` won't save any changes because attaching leaves the entity in state `Unchanged`. You must set the state to `Modified` after `Attach`. But this is ineffective since all columns will be updated no matter if they really did change. To avoid this you have to load the original into the context and apply the changes on property level. But then you don't need `Exists` since it would only cause to load the entity twice. And what will you do when `entity` has navigation properties and related objects have to be updated or not? I have doubt in a generic `Save` approach.
      singulars
    2. CO@Yuck: I'm only talking about the "if"-case, not the "else"-case of course. I don't see how this could save anything, it even won't issue any SQL command to the database. Quote from here: http://blogs.msdn.com/b/adonet/archive/2011/01/29/using-dbcontext-in-ef-feature-ctp5-part-4-add-attach-and-entity-states.aspx **...Note that no changes will be made to the database if SaveChanges is called without doing any other manipulation of the attached entity. This is because the entity is in the Unchanged state...** And I can confirm this from my own tests.
      singulars
    3. CO@Yuck: No, that's wrong. It doesn't update. If you have a `User` in the database with `Id` = 1 and `Name` = "Paul" and then *attach* a `User` entity with `Id` = 1 and `Name` = "Mary" to the context and then directly call `SaveChanges`, the `User` with `Id` = 1 in the database still has the name "Paul". (I'm talking about EF 4.1 too, but it doesn't matter, this behaviour is EF core stuff.)
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload