Skip to content

Instantly share code, notes, and snippets.

@winnicki
Created September 2, 2017 18:24
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 winnicki/2392cb561ac5aa919bc27ce8ee652ae2 to your computer and use it in GitHub Desktop.
Save winnicki/2392cb561ac5aa919bc27ce8ee652ae2 to your computer and use it in GitHub Desktop.
LINQ to JSON Upsert
public async Task SaveLocation(JObject locationJObject, int locationId)
{
await Task.Run(() =>
{
var companyJObject = JObject.Parse(RawJson.Company);
companyJObject[nameof(Company.Locations)]?
.FirstOrDefault(x => (decimal)x[nameof(Location.Id)] == locationId)
.Replace(locationJObject);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment