title: Mixing EF Core Convensions and DBFunction for a JObject property
body: <p>I have an entity with properties of type JObject and I need to be able to use DbFunctions against those properties. </p>
  
  <p>When I execute, the project throws an exception saying that DbFunction doesn't allows parameters of type JObject. </p>
  
  <p>The <strong>entity</strong> is like...</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class OrchestrationRun
  {
     public long Id { get; set; }
      public JObject MetaData { get; set; }
      public JObject SystemMetaData { get; set; }
  }
  </code></pre>
  
  <p>The <strong>DbContext</strong> looks like...</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class MyDbContext : DbContext
  {
      public MyDbContext(DbContextOptions options)
          : base(options)
      {
      }
  
      public virtual DbSet&lt;OrchestrationRun&gt; OrchestrationRun { get; set; }
  
      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          modelBuilder.ApplyConfiguration(new OrchestrationRunConfiguration());
  
         // DbFunction mapping for JSON_VALUE
         modelBuilder.HasDbFunction( typeof(MyDbContext).GetMethod(nameof(JsonValue)))
                        .HasName("JSON_VALUE")
                        .HasSchema("");
      }
  
      // DbFunction
      public static string JsonValue(JObject column, [NotParameterized] string path) =&gt; throw new NotSupportedException();
  }
  </code></pre>
  
  <p>The <strong>OrchestrationRunConfiguration</strong> is ...
  </p>
  
  <pre><code>public class OrchestrationRunConfiguration : IEntityTypeConfiguration&lt;OrchestrationRun&gt;
  {
      public void Configure(EntityTypeBuilder&lt;OrchestrationRun&gt; builder)
      {
          builder.Property(e =&gt; e.MetaData).HasConversion(
              jObject =&gt; jObject != null ? jObject.ToString(Formatting.None) : null,
              json =&gt; string.IsNullOrWhiteSpace(json) ? null : JObject.Parse(json)
          );
  
          builder.Property(e =&gt; e.SystemMetaData).HasConversion(
               jObject =&gt; jObject != null ? jObject.ToString(Formatting.None): null,
               json =&gt; string.IsNullOrWhiteSpace(json) ? null : JObject.Parse(json)
           );
      }
  }
  </code></pre>
  
  <p>The query I'm trying to execute is... 
  </p>
  
  <pre><code>var dbResponse = (from or in this.dbContext.OrchestrationRun
  where MyDbContext.JsonValue(or.MetaData,"$.Product.ProductCategoryName") == "EXAMPLE"
  select new
         {
            Id = or.Id,
            CategoryId = "EXAMPLE"
         }
  
      ).ToList();
  </code></pre>
  
  <p><strong><em>Note:</strong> The exception occurs at DbContext instantiation. Therefore the query is never called.</em></p>
  
  <p>The exception thrown is...</p>
  
  <blockquote>
    <p>System.InvalidOperationException: The parameter 'column' for the DbFunction 'MyDbContext.JsonValue' has an invalid type 'JObject'. Ensure the parameter type can be mapped by the current provider.
    at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.ValidateDbFunctions(IModel model)
    at Microsoft.EntityFrameworkCore.Internal.SqlServerModelValidator.Validate(IModel model)
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ValidatingConvention.Apply(InternalModelBuilder modelBuilder)</p>
  </blockquote>