Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added working example of adding interface to DataServiceQuery with ex… #1578

Open
wants to merge 1 commit into
base: release-7.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/Microsoft.OData.Client/DataServiceQueryOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ namespace Microsoft.OData.Client
using System.Reflection;
using System.Threading.Tasks;

public interface IDataServiceQuery<TElement> : IQueryable<TElement>
{
IDataServiceQuery<TElement> Expand(string path);
IDataServiceQuery<TElement> Expand<TTarget>(Expression<Func<TElement, TTarget>> navigationPropertyAccessor);
Task<IEnumerable<TElement>> ExecuteAsync();
//DataServiceContext Context { get; }
}

/// <summary>
/// query object
/// </summary>
/// <typeparam name="TElement">type of object to materialize</typeparam>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "required for this feature")]
public class DataServiceQuery<TElement> : DataServiceQuery, IQueryable<TElement>
public class DataServiceQuery<TElement> : DataServiceQuery, IQueryable<TElement>, IDataServiceQuery<TElement>
{
#region Private fields

Expand Down Expand Up @@ -277,6 +285,13 @@ public IEnumerable<TElement> GetAllPages()
}
#endif

/// <summary>Expands a query to include entities from a related entity set in the query response.</summary>
/// <returns>A new query that includes the requested $expand query option appended to the URI of the supplied query.</returns>
/// <param name="path">The expand path in the format Orders/Order_Details.</param>
IDataServiceQuery<TElement> IDataServiceQuery<TElement>.Expand(string path)
{
return Expand(path) as IDataServiceQuery<TElement>;
}
/// <summary>Expands a query to include entities from a related entity set in the query response.</summary>
/// <returns>A new query that includes the requested $expand query option appended to the URI of the supplied query.</returns>
/// <param name="path">The expand path in the format Orders/Order_Details.</param>
Expand All @@ -297,6 +312,10 @@ public DataServiceQuery<TElement> Expand(string path)
/// <param name="navigationPropertyAccessor">A lambda expression that indicates the navigation property that returns the entity set to include in the expanded query.</param>
/// <typeparam name="TTarget">Target type of the last property on the expand path.</typeparam>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By design")]
IDataServiceQuery<TElement> IDataServiceQuery<TElement>.Expand<TTarget>(Expression<Func<TElement, TTarget>> navigationPropertyAccessor)
{
return Expand(navigationPropertyAccessor) as IDataServiceQuery<TElement>;
}
public DataServiceQuery<TElement> Expand<TTarget>(Expression<Func<TElement, TTarget>> navigationPropertyAccessor)
{
Util.CheckArgumentNull(navigationPropertyAccessor, "navigationPropertyAccessor");
Expand Down
Loading