title: Entity Framework Core PostgreSQL Linq to SQL Json Field
body: <p>Sorry for my bad English</p>
  
  <p>Note: Npgsql does not supporting json query with EF Core Mapping directly</p>
  
  <p>As yo know PostgreSQL is supporting json and hybrid data. And if you want to query, you can use syntax like this</p>
  
  <pre><code>select * 
  from archive.ArchiveObject 
  where FileInfo-&gt;&gt;'FileName' = 'name.ext';
  </code></pre>
  
  <p>For my question here is sample table and sample class</p>
  
  <p>Table: </p>
  
  <pre><code>CREATE TABLE archive."ArchiveObject"
  (
      "Id" bigint NOT NULL DEFAULT nextval('archive."ArchiveObject_Id_seq"'::regclass),
      "Uid" uuid NOT NULL,
      ...
      ...
      ...
      "FileInfo" json,
      ...
      ...
  
  )
  </code></pre>
  
  <p>and here is C#  classes for this table</p>
  
  <pre><code>[Table("ArchiveObject", Schema = CX.Schema)]
  public partial class ArchiveObject
  {
          [Key]
          public long Id { get; set; }
          [Required]
          public Guid Uid { get; set; }
          [Column("FileInfo", TypeName = "json")]
          public string _FileInfo { get; set; }
  
          [NotMapped]
          public ObjectFileInfo FileInfo
          {
              //get;set;
              get
              {
                  return string.IsNullOrEmpty(_FileInfo) ? null : JsonConvert.DeserializeObject&lt;ObjectFileInfo&gt;(_FileInfo);
              }
              set
              {
                  _FileInfo = value != null ? JsonConvert.SerializeObject(value) : null;
              }
          }
  ...
  ...
  }
  </code></pre>
  
  <p>OK. When I used linq or lambda like this no problem</p>
  
  <pre><code>var query = from x in db.ArchiveObject 
              where x.Id &lt; 65535
              select x;
  </code></pre>
  
  <p>generates</p>
  
  <pre><code>"SELECT x."Id", x."CreatedAt", x."KellePaca", x."Tags", x."Uid", x."UpdateHistory", x."VirtualPathId", x."FileInfo"
   FROM archive."ArchiveObject" AS x
   WHERE (x."Id" &lt; 65535)
  </code></pre>
  
  <p>but I can't query json area named FileInfo field like this.</p>
  
  <pre><code>select * 
  from archive.ArchiveObject 
  where FileInfo-&gt;&gt;'FileName' = 'name.ext'    ;
  </code></pre>
  
  <p>because of EF doesn't have any Provider for convert to sql "file_info->>'FileName'"</p>
  
  <p>I'm searched and found this terms </p>
  
  <pre><code>ExpressionVisitor, QueryProvider, BinaryExpression,
  ParameterExpression, ObjectQuery.ToTraceString, Expression
  </code></pre>
  
  <p>and also found this documents and answers</p>
  
  <p><a href="https://stackoverflow.com/questions/7731905/how-to-convert-an-expression-tree-to-a-partial-sql-query">How to convert an expression tree to a partial SQL query?</a></p>
  
  <p><a href="https://www.codeproject.com/Articles/22819/How-To-LINQ-To-SQL-Part-III" rel="nofollow noreferrer">https://www.codeproject.com/Articles/22819/How-To-LINQ-To-SQL-Part-III</a></p>
  
  <p>I'm believe can be generate [ file_info->>'FileName' = 'name.ext'   ; ] query using this documents. But I can't get it.</p>
  
  <pre><code>public static IQueryable&lt;ArchiveObject&gt; FileNameEquals(this IQueryable&lt;ArchiveObject&gt; source, string s)
          {
             ....
          }
      or what?
  </code></pre>
  
  <p>Please can you show me simple example. </p>