Skip to content

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.

/// 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.

}

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.

// 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.

/// <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?

/// <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.

/// <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.

4 participants