Comments (5)
@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.
@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.
Closing as no additional info was provided, but feel free to post back here and I'll reopen if necessary.
from efcore.pg.
@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.
@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)
- Unable to Fetch Data from Stored Procedure with Cursor as return type and getting required column id was not present in the results of a "FromSql" operation.
- Implement migration locking
- Replace type reloading mechanism with the new EF migration extensibility mechanism
- DateOnly - en_GB date flipped from October to April. HOT 2
- LTree column type doens worked with migration
- Errors on mapping enum types to SQL and storing into database
- Is there way to translate EF Core query to WITH Queries (Common Table Expressions) ? HOT 3
- Select or filter Length of string contained in JsonB column
- Value Conversion Not Applied when using DbFunction in EF Core HOT 1
- ExecuteDelete cloud not betranslated but querying can HOT 3
- Warning: Found conflicts between different versions of "Microsoft.EntityFrameworkCore.Relational" that could not be resolved on Microsoft.EntityFrameworkCore.Relational 8.0.4 and 8.0.7 HOT 4
- Received backend message ParseComplete while expecting BindCompleteMessage using pgcat pooler
- Guidance for NodaTime postgres data types HOT 3
- v8.0.4 - First async query to run fails HOT 1
- SRID is ignored when writing NetTopologySuite Geometry properties inside objects mapped with ToJson()
- Is Npgsql.EntityFrameworkCore.PostgreSQL stop updating? HOT 2
- Null value in column of relation table violates not-null constraint HOT 11
- Issue Configuring `EnableDynamicJson()` on Data Source with a Multi-Tenant API Leveraging Postgres Row-Level Security
- EF not persisting updating value converted collections to JSON HOT 6
- How to handle Enum in .net core with entity framework USING PostgreSQL HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from efcore.pg.