Esempio n. 1
0
 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));
         }
     }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }