sdk/dotnet/src/Microsoft.Datasync.Client/Query/OData/QueryDescriptionExtensions.cs
/// <summary>
/// Converts the query structure into a standard OData URI protocol for queries.
/// </summary>
/// <param name="value">The <see cref="QueryDescription"/> to convert to OData.</param>
/// <param name="parameters">A list of optional parameters to include in the query string.</param>
/// <returns>A URI query string representing the query.</returns>
Converts the query structure into a standard OData URI protocol for queries.
Converts the query structure into a standard OData URI protocol for queries .
public static string ToODataString(this QueryDescription value, IDictionary<string, string> parameters = null)
        {
            List<string> queryFragments = new();
            if (value.Filter != null)
            {
                string filterStr = ODataExpressionVisitor.ToODataString(value.Filter);
                queryFragments.Add($"{ODataOptions.Filter}={filterStr}");
            }
            if (value.Ordering.Count > 0)
            {
                var orderings = value.Ordering.Select(o => o.ToODataString());
                queryFragments.Add($"{ODataOptions.OrderBy}={string.Join(",", orderings)}");
            }
            if (value.Skip.HasValue && value.Skip >= 0)
            {
                queryFragments.Add($"{ODataOptions.Skip}={value.Skip}");
            }
            if (value.Top.HasValue && value.Top >= 0)
            {
                queryFragments.Add($"{ODataOptions.Top}={value.Top}");
            }
            if (value.Selection.Count > 0)
            {
                queryFragments.Add($"{ODataOptions.Select}={string.Join(",", value.Selection.Select(Uri.EscapeDataString))}");
            }
            if (value.IncludeTotalCount)
            {
                queryFragments.Add($"{ODataOptions.InlineCount}=true");
            }
            if (parameters?.Count > 0)
            {
                foreach (var kv in parameters)
                {
                    queryFragments.Add($"{Uri.EscapeDataString(kv.Key)}={Uri.EscapeDataString(kv.Value)}");
                }
            }
            return string.Join("&", queryFragments);
        }
public static string ToODataString ( this QueryDescription value , IDictionary < string , string > parameters = null ) { List < string > queryFragments = new ( ) ; if ( value . Filter != null ) { string filterStr = ODataExpressionVisitor . ToODataString ( value . Filter ) ; queryFragments . Add ( $" { ODataOptions . Filter } = { filterStr } " ) ; } if ( value . Ordering . Count > 0 ) { var orderings = value . Ordering . Select ( o => o . ToODataString ( ) ) ; queryFragments . Add ( $" { ODataOptions . OrderBy } = { string . Join ( " " , orderings ) } " ) ; } if ( value . Skip . HasValue && value . Skip >= 0 ) { queryFragments . Add ( $" { ODataOptions . Skip } = { value . Skip } " ) ; } if ( value . Top . HasValue && value . Top >= 0 ) { queryFragments . Add ( $" { ODataOptions . Top } = { value . Top } " ) ; } if ( value . Selection . Count > 0 ) { queryFragments . Add ( $" { ODataOptions . Select } = { string . Join ( " " , value . Selection . Select ( Uri . EscapeDataString ) ) } " ) ; } if ( value . IncludeTotalCount ) { queryFragments . Add ( $" { ODataOptions . InlineCount } =true " ) ; } if ( parameters ? . Count > 0 ) { foreach ( var kv in parameters ) { queryFragments . Add ( $" { Uri . EscapeDataString ( kv . Key ) } = { Uri . EscapeDataString ( kv . Value ) } " ) ; } } return string . Join ( " " , queryFragments ) ; }
Converts the query structure into a standard OData URI protocol for queries.
Converts the query structure into a standard OData URI protocol for queries .
A URI query string representing the query.
A URI query string representing the query .
QueryDescription
this
parameters
IDictionary<string, string>
A list of optional parameters to include in the query string.
A list of optional parameters to include in the query string .
value
The  to convert to OData.
The to convert to OData .