Entity Framework DbFunction and NotParameterized attribute on Oracle

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
fabien.menager
Posts: 4
Joined: Mon 25 Jun 2018 14:39

Entity Framework DbFunction and NotParameterized attribute on Oracle

Post by fabien.menager » Mon 25 Jun 2018 14:51

Hello, I have an extension to my ModelBuilder declaring a DB function (JSON_VALUE) which allows the use of JSON_VALUE in Entity Framework :

Code: Select all

using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;

namespace Lib.Extensions
{
    public static class EfExtensions
    {
        /// <summary>
        ///     JSON_VALUE function for EF
        ///     https://github.com/aspnet/EntityFrameworkCore/issues/11295#issuecomment-373852015
        /// </summary>
        public static string JsonValue(string column, [NotParameterized] string path)
        {
		// C# implementation, not important for the current issue
        }

        /// <summary>
        ///     Adds support for JSON_VALUE inside EF queries on this DB context
        /// </summary>
        /// <example>
        ///     query.Where(_ => _.Reference != null && EfExtensions.JsonValue(_.Reference, $"$.{key}") == value)
        /// </example>
        public static void AddJsonValue(ModelBuilder bld)
        {
            bld.HasDbFunction(typeof(EfExtensions).GetMethod(nameof(JsonValue)))
                .HasName("JSON_VALUE")
                .HasSchema("");
        }
    }
}
I use the latest NuGet package (Devart.Data.Oracle v9.6.540)

My problem is that it works on SQL Server, where EF generates this kind of SQL :

Code: Select all

	WHERE (JSON_VALUE("_".REFERENCE, N'$.AffaireId') = @p__ToString_0))
while I get this on Oracle :

Code: Select all

	WHERE (JSON_VALUE("_".REFERENCE, $.AffaireId) = :p__ToString_0))
Which gives me a "ORA-00911: invalid character", because the $.AffaireId is not encapsulated by quotes.

What am I missing ?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Entity Framework DbFunction and NotParameterized attribute on Oracle

Post by Shalex » Thu 28 Jun 2018 18:42

Thank you for your report. We have reproduced the issue and are investigating it.

fabien.menager
Posts: 4
Joined: Mon 25 Jun 2018 14:39

Re: Entity Framework DbFunction and NotParameterized attribute on Oracle

Post by fabien.menager » Thu 12 Jul 2018 08:42

Ok, great !
Do you have a planning for this fix ?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Entity Framework DbFunction and NotParameterized attribute on Oracle

Post by Shalex » Fri 13 Jul 2018 19:16

The bug with processing arguments of functions mapped via .HasDbFunction is fixed. The internal build with the fix: https://www.devart.com/pub/nuget_oracle_9_6_554.zip.

fabien.menager
Posts: 4
Joined: Mon 25 Jun 2018 14:39

Re: Entity Framework DbFunction and NotParameterized attribute on Oracle

Post by fabien.menager » Thu 19 Jul 2018 12:07

I saw you released a new version of the NuGET package, it works fine, thank you very much ! \o/

https://www.nuget.org/packages/Devart.Data.Oracle/

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Entity Framework DbFunction and NotParameterized attribute on Oracle

Post by Shalex » Fri 20 Jul 2018 09:25

You are welcome! For more information, refer to viewtopic.php?f=1&t=37474.

Post Reply