Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using json type to serialize data #106

Closed
ma3yta opened this issue Sep 28, 2016 · 3 comments
Closed

Using json type to serialize data #106

ma3yta opened this issue Sep 28, 2016 · 3 comments

Comments

@ma3yta
Copy link

ma3yta commented Sep 28, 2016

dotnet/efcore#5868

Does this scenario supported by Npgsql.EntityFrameworkCore.PostgreSQL?

I run Add-Migrations and this command produce few fields(Address_Stree, Address_Country) instead one for serialized data:

public class Cat
    {
        public Guid Id { get; set; }
        public string Name { get; set; }

        [Column(TypeName = "json")]
        public Address Address { get; set; }
    }

    public class Address
    {
        public string Street { get; set; }
        public string Country { get; set; }
    }
public override void Up()
        {
            CreateTable(
                "public.Cats",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(),
                        Address_Street = c.String(),
                        Address_Country = c.String(),
                    })
                .PrimaryKey(t => t.Id);

            CreateTable(
                "public.Users",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(),
                        Email = c.String(),
                    })
                .PrimaryKey(t => t.Id);

        }
@roji
Copy link
Member

roji commented Sep 28, 2016

Nope, that won't work - nobody knows how to magically convert your Address class into a PostgreSQL json column. This would be similar to dotnet/efcore#4021.

If you don't really care about JSON but just want to store a class/struct in a PostgreSQL column, you may want to look at composite support - that's not working yet either but will very probably make it into the 1.1.0 release.

Am going to close this as it needs attention in a more EFCore general way and not just in Npgsql.

@roji roji closed this as completed Sep 28, 2016
@roji roji added the invalid label Sep 28, 2016
@idudinov
Copy link

Hi @roji ! Is your resolution for this issue still actual?

nobody knows how to magically convert your Address class into a PostgreSQL json column

I mean, in the light of this new feature http://www.npgsql.org/doc/types/jsonnet.html - supporting JSON.NET serialization, and new versions of EF Core, have things been changed somehow?

Thanks!

@roji
Copy link
Member

roji commented May 21, 2018

@idudinov JSON.NET will provide automatic JSON serialization at the ADO.NET layer, but there's no support for it yet at the EF Core level (see #334 for details). So unfortunately this is still not supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants