Right. scope_identity() exists to get the generated CustomerId value, so EF can use it as an entity key. I think, but I have to guess, because it is not documented, SELECT is performed in the Customer table to make sure that the extracted scope_identity() actually associated with CustomerId . There may be times when INSERT triggers more inserts, so scope_identity() is allocated to another record.
The second reason for querying the Customer table is that this query is generated by a single method, which can also add computed columns to the SELECT clause. It would probably be more convenient to always query the entity table.
The WHERE @@ROWCOUNT > 0 added to ensure that the expected number of rows depends on the INSERT . There is a comment in the EF source code:
Note that we are filtering on rowcount to ensure that no rows will be returned if no rows have been changed.
source share