Skip to content

Instantly share code, notes, and snippets.

@johnknoop
Last active March 23, 2022 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnknoop/4c07e80625de8f92746053e23e1ced9d to your computer and use it in GitHub Desktop.
Save johnknoop/4c07e80625de8f92746053e23e1ced9d to your computer and use it in GitHub Desktop.
Upsert all in one db roundtrip
public async Task<IActionResult> Upsert(BulkUpsertRequest request)
{
request.Devices.ForEach(d =>
{
var device = new Device(d.Id, d.Name, d.Metadata.Select(...));
_dbContext.Entry(device).IsModified = true;
})
await _dbContext.SaveAsync();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment