Thanks for maintaining this library, I just started using it yesterday and am a little bit in disbelief at how easy it was to drop into an EFCore Project.
I'm working with SqlServer Json functionality and hit a few issues with dbfunctions.
It appears .ToLinqToDB() doesn't pick up functions that are mapped via expression.
This does not work, it renders with the name "JsonValue":
modelBuilder.HasDbFunction(typeof(DbJson).GetMethod(nameof(DbJson.JsonValue)))
.HasTranslation(e => SqlFunctionExpression.Create(
"JSON_VALUE", e, typeof(string), null));
This does work, so I do have a workaround for now since my method signature didn't actually need to be mapped:
modelBuilder.HasDbFunction(typeof(DbJson).GetMethod(nameof(DbJson.JsonValue))).HasName("JSON_VALUE");
// --- other file
[Expression("JSON_VALUE({column},{path})", ServerSideOnly = true)]
public static string JsonValue(string column, [NotParameterized] string path)
{
throw new NotSupportedException();
}
I don't know if there is interplay between mapping functions using Sql.ExpressionAttribute / Sql.FunctionAttribute / Sql.ExtensionsAttribute, but I first tried to fix it by adding those to the method, and they appear to do nothing if you put them on a method that the DbContext is already mapping, but I was expecting them to override the normal DbContext behavior.
The NotParameterized attribute from EfCore appears to not be respected:
public static string JsonValue(string column, [NotParameterized] string path)
{
throw new NotSupportedException();
}
renders to sql like
JSON_VALUE([a_Product].[Json], @path_1)
but I read it is important that the "path" argument doesn't get parameterized so that the query optimizer will to use computed Json indexes. If you have any ideas on a workaround that could force rendering it like
JSON_VALUE([a_Product].[Json], N'Actual String Value Of "path"')
please let me know because this one has me stumped.
Thanks for maintaining this library, I just started using it yesterday and am a little bit in disbelief at how easy it was to drop into an EFCore Project.
I'm working with SqlServer Json functionality and hit a few issues with dbfunctions.
This does not work, it renders with the name "JsonValue":
This does work, so I do have a workaround for now since my method signature didn't actually need to be mapped:
I don't know if there is interplay between mapping functions using Sql.ExpressionAttribute / Sql.FunctionAttribute / Sql.ExtensionsAttribute, but I first tried to fix it by adding those to the method, and they appear to do nothing if you put them on a method that the DbContext is already mapping, but I was expecting them to override the normal DbContext behavior.
The NotParameterized attribute from EfCore appears to not be respected:
renders to sql like
but I read it is important that the "path" argument doesn't get parameterized so that the query optimizer will to use computed Json indexes. If you have any ideas on a workaround that could force rendering it like
please let me know because this one has me stumped.