In the section "Option 3 - Add state verification", the code block uses verifySucceeded to check if a Blog exists with aBlogId equal to blogToAdd.BlogId. Due to acceptAllChangesOnSuccess being set to false, I believe the store-generated blogToAdd.BlogId will still be 0 at this point and this check will always fail, or at least will be the wrong check to make. There could be a few ways to improve the example but one might be to use db.Entry(blogToAdd).CurrentValues[nameof(Blog.BlogId)] as I think this will have the store-generated value in it.
Also, if my understanding is correct, AsNoTracking() is redundant here as no entity is returned by the query. Would it be best to remove this, not just for brevity but so as to avoid any confusion about its function?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
In the section "Option 3 - Add state verification", the code block uses
verifySucceededto check if aBlogexists with aBlogIdequal toblogToAdd.BlogId. Due toacceptAllChangesOnSuccessbeing set to false, I believe the store-generatedblogToAdd.BlogIdwill still be 0 at this point and this check will always fail, or at least will be the wrong check to make. There could be a few ways to improve the example but one might be to usedb.Entry(blogToAdd).CurrentValues[nameof(Blog.BlogId)]as I think this will have the store-generated value in it.Also, if my understanding is correct,
AsNoTracking()is redundant here as no entity is returned by the query. Would it be best to remove this, not just for brevity but so as to avoid any confusion about its function?Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.