private static void TraverseJObject(JObject jObject, Dictionary <string, string> keyValuePairs, string parentPath) { foreach (var property in jObject.Properties()) { var propertyPath = parentPath != null ? parentPath + PathDelimiter + property.Name : property.Name; if (property.Value.Type == JTokenType.Object) { TraverseJObject((JObject)property.Value, keyValuePairs, propertyPath); } else { keyValuePairs.Add(propertyPath, JTokenStringify.Stringify(property.Value)); } } }
public static string CreateFromDataAndTableSetup(BsonDocument data, SqlTableSetup tableSetup, string id) { var jObject = JObject.Parse(DataEncoder.DecodeToJson(data)); var properties = jObject.Properties().Where(property => property.Name != tableSetup.IdColumnName).ToList(); var keyValuePairs = string.Join(", ", properties.Where(property => property.Name != tableSetup.IdColumnName) .ToDictionary(property => property.Name, property => JTokenStringify.Stringify(property.Value)) .Select(kvp => $"{kvp.Key} = '{kvp.Value}'")); var query = $"UPDATE {tableSetup.TableName} SET {keyValuePairs} WHERE {tableSetup.IdColumnName} = '{id}'"; return(query); }
public static string CreateFromDataAndTableSetup(BsonDocument data, SqlTableSetup tableSetup) { var jObject = JObject.Parse(DataEncoder.DecodeToJson(data)); var properties = jObject.Properties().Where(property => property.Name != tableSetup.IdColumnName).ToList(); var query = $"INSERT INTO {tableSetup.TableName} ({string.Join(", ", properties.Select(property => property.Name))}) " + $"OUTPUT INSERTED.{tableSetup.IdColumnName} " + $"VALUES ({string.Join(", ", properties.Select(property => $"'{JTokenStringify.Stringify(property.Value)}'"))})"; return(query); }