GithubHelp home page GithubHelp logo

Comments (5)

chances avatar chances commented on August 20, 2024 1

@roji Ah, you're right. I tried to reproduce the error I was seeing with a simpler case and discovered the problem is with this upsert library. It's treating the string-backed JSON property as a text column in its PostgreSQL query generator.

Thank you for helping me look at the problem from a different angle. 😀

from efcore.pg.

roji avatar roji commented on August 20, 2024

@balaji8, sorry for not answering this sooner. The recently released RC2 version of the provider has tests which successfully roundtrip a jsonb field, this problem was probably resolved at some point. Can you please check with that version and confirm?

from efcore.pg.

roji avatar roji commented on August 20, 2024

Closing as no additional info was provided, but feel free to post back here and I'll reopen if necessary.

from efcore.pg.

chances avatar chances commented on August 20, 2024

@roji I'm experiencing this issue with the latest version of Npgsql.EntityFrameworkCore.PostgreSQL, v2.1.1.1

Inserting a new record throws this error: Npgsql.PostgresException: 42804: column "spotify_user" is of type json but expression is of type text

I am using models generated with the EF Core scaffold tool:

[Table("user")]
public partial class User
{
    [Column("id")]
    public long Id { get; set; }
    [Required]
    [Column("spotify_user", TypeName = "json")]
    public string SpotifyUser { get; set; }
    [Required]
    [Column("access_token", TypeName = "character varying")]
    public string AccessToken { get; set; }
    [Column("created_at", TypeName = "timestamp with time zone")]
    public DateTime CreatedAt { get; set; }
    [Column("updated_at", TypeName = "timestamp with time zone")]
    public DateTime UpdatedAt { get; set; }
}

Adding entity.Property(p => p.SpotifyUser).HasColumnType("json"); in OnModelCreating does not resolve the issue.

from efcore.pg.

roji avatar roji commented on August 20, 2024

@chances the following code works fine:

class Program
{
    static void Main(string[] args)
    {
        using (var ctx = new BlogContext())
        {
            ctx.Database.EnsureDeleted();
            ctx.Database.EnsureCreated();

            ctx.Blogs.Add(new Blog { Name = "{ \"key\" : \"value\" }" });
            ctx.SaveChanges();
        }

        Console.WriteLine("Done");
    }
}

public class Blog
{
    public int Id { get; set; }
    [Column(TypeName = "json")]
    public string Name { get; set; }
}

public class BlogContext : DbContext
{
    public DbSet<Blog> Blogs { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder builder)
        => builder.UseNpgsql(ConnectionString);
}

Can you please double-check the code and versions you're using, and if the issue persists, post a full code sample which triggers the issue?

from efcore.pg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.