-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
How to use multiple IMethodCallTranslatorProvider #23275
Comments
Use true plugin infrastructure. Rather than replacing service of IMethodCallTranslatorProvider, add a service implementation for IMethodCallTranslatorPlugin. See https://github.com/dotnet/efcore/blob/main/src/EFCore.Sqlite.NTS/Query/Internal/SqliteNetTopologySuiteMethodCallTranslatorPlugin.cs for example. |
Perfect! Just extending IMethodCallTranslatorPlugin worked like a charm! public class CustomMethodCallTranslatorPlugin : IMethodCallTranslatorPlugin
{
public CustomMethodCallTranslatorPlugin(ISqlExpressionFactory sqlExpressionFactory)
{
Translators = new IMethodCallTranslator[]
{
new ConvertToIntTranslator(sqlExpressionFactory),
new StringSubStringTranslator(sqlExpressionFactory)
};
}
public virtual IEnumerable<IMethodCallTranslator> Translators { get; }
} and adding the service with void IDbContextOptionsExtension.ApplyServices(IServiceCollection services)
{
services.AddSingleton<IMethodCallTranslatorPlugin, CustomMethodCallTranslatorPlugin>();
} Thank you very much! |
If you're looking for simple additional function translations, there's also the approach of using DbFunction, which may be lighter/more appropriate. The docs for that are still in progress (dotnet/EntityFramework.Docs#500), but it entails invoking |
I've also seen this approach. I think for now is better for us to use IMethodCallTranslatorPlugin. It let us organize our code better and is pretty straight foward to add a new translator once the extensions are coded. Thanks for your input! |
Ask a question
Hello, we are using Oracle provider for EF Core 3.1 and would like to add our custom IMethodCallTranslatorProvider so we can extend more functions to be translated as SQL.
Adding our translator through
makes EF completly ignore Oracle's OracleMethodCallTranslatorProvider
Is there a way to register another provider or custom translators to be used alongside Oracle's ?
Right now our solution is to male our coustom provider to extend OracleMethodCallTranslatorProvider, but this is not ideal as this class is internal and could change on a future Oracle SQL Proovider update
Include your code
The text was updated successfully, but these errors were encountered: