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

Make internal SelectExpandBinder methods public #840

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bdebaere
Copy link

Because so many methods are marked internal it really makes expanding OData behavior quite a hassle. I implore you to take a look at how extensible EntityFrameworkCore is for example and to reconsider all these internal methods everywhere.

@xuzhg
Copy link
Member

xuzhg commented Feb 13, 2023

Because so many methods are marked internal it really makes expanding OData behavior quite a hassle. I implore you to take a look at how extensible EntityFrameworkCore is for example and to reconsider all these internal methods everywhere.

Can you point me to any EFCore example? Thanks.

@bdebaere
Copy link
Author

@xuzhg EntityFrameworkCore has a ServiceCollection where you can add stuff to with for example IDbContextOptionsExtension.ApplyServices(IServiceCollection services). OData has a similar thing where you can add or replace services with ODataOptions.AddRouteComponents(string routePrefix, IEdmModel model, Action<IServiceCollection> configureServices) and this is great!

However, I think you don't take it far enough. Take a look at these EntityFrameworkCore classes/interfaces:

  • RelationalQueryTranslationPreprocessor
  • RelationalSqlTranslatingExpressionVisitor
  • SqlServerQuerySqlGenerator
  • IMemberTranslatorPlugin
  • IRelationalTypeMappingSourcePlugin

They allow extending because the necessary methods are public. Too many methods/classes are internal in OData which makes extending it without a custom copy of the code very difficult sometimes.

@@ -44,7 +44,7 @@ public SelectExpandBinder(IFilterBinder filterBinder, IOrderByBinder orderByBind
/// <summary>
/// For unit test only.
/// </summary>
internal SelectExpandBinder()
public SelectExpandBinder()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to make this method public since it's only used internally with some tests.

@@ -89,7 +89,7 @@ public virtual Expression BindSelectExpand(SelectExpandClause selectExpandClause
return projectionLambdaExpression;
}

internal Expression ProjectAsWrapper(QueryBinderContext context, Expression source, SelectExpandClause selectExpandClause,
public Expression ProjectAsWrapper(QueryBinderContext context, Expression source, SelectExpandClause selectExpandClause,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make method virtual and add docstrings.

@@ -336,7 +336,7 @@ public class Child : Father

// Generates the expression
// source => new Wrapper { Instance = source, Container = new PropertyContainer { ..expanded properties.. } }
internal Expression ProjectElement(QueryBinderContext context, Expression source, SelectExpandClause selectExpandClause, IEdmStructuredType structuredType, IEdmNavigationSource navigationSource)
public Expression ProjectElement(QueryBinderContext context, Expression source, SelectExpandClause selectExpandClause, IEdmStructuredType structuredType, IEdmNavigationSource navigationSource)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make method virtual and add docstrings.

@@ -476,7 +476,7 @@ internal Expression ProjectElement(QueryBinderContext context, Expression source
/// <param name="propertiesToExpand">The out properties to expand at current level, could be null.</param>
/// <param name="autoSelectedProperties">The out auto selected properties to include at current level, could be null.</param>
/// <returns>true if the select contains dynamic property selection, false if it's not.</returns>
internal static IList<DynamicPathSegment> GetSelectExpandProperties(IEdmModel model, IEdmStructuredType structuredType, IEdmNavigationSource navigationSource,
public static IList<DynamicPathSegment> GetSelectExpandProperties(IEdmModel model, IEdmStructuredType structuredType, IEdmNavigationSource navigationSource,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is static and cannot be overriden. How do you plan to use it?

@@ -829,7 +829,7 @@ public virtual Expression CreateTotalCountExpression(QueryBinderContext context,
/// <param name="navigationProperty">The expanded navigation property.</param>
/// <param name="expandedItem">The expanded navigation select item. It may contain the nested query options.</param>
/// <param name="includedProperties">The container to hold the created property.</param>
internal void BuildExpandedProperty(QueryBinderContext context, Expression source, IEdmStructuredType structuredType,
public void BuildExpandedProperty(QueryBinderContext context, Expression source, IEdmStructuredType structuredType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make method virtual.

@@ -909,7 +909,7 @@ public virtual Expression CreateTotalCountExpression(QueryBinderContext context,
/// <param name="structuralProperty">The selected structural property.</param>
/// <param name="pathSelectItem">The selected item. It may contain the nested query options and could be null.</param>
/// <param name="includedProperties">The container to hold the created property.</param>
internal void BuildSelectedProperty(QueryBinderContext context, Expression source, IEdmStructuredType structuredType,
public void BuildSelectedProperty(QueryBinderContext context, Expression source, IEdmStructuredType structuredType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make method virtual.

@gathogojr
Copy link
Contributor

@bdebaere Did you get a chance to look at the feedback from @KenitoInc?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants