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

An enum property isn't mapped to the PostgreSQL enum inside value objects #623

Closed
YohDeadfall opened this issue Aug 31, 2018 · 11 comments
Closed
Assignees

Comments

@YohDeadfall
Copy link
Contributor

The problem occurs only for value objects inside complex objects. The following example maps PhoneNumberType to int:

public enum PhoneNumberType
{
    Mobile,
    Home,
    Work
}

public class PhoneNumber
{
    public PhoneNumberType Type { get; set; }
    public int Number { get; set; }
}

public class Contact
{
    public PhoneNumber Phone { get; set; }
}
builder.OwnsOne(e => e.Phone).Property(p => p.Type);
builder.OwnsOne(e => e.Phone).Property(p => p.Number);
@austindrenski
Copy link
Contributor

@YohDeadfall Do you mind if I wrap this into #605 which attempts to address some other enum edge cases?

@YohDeadfall
Copy link
Contributor Author

I think that such changes should be made by separate pull requests. One issue - one request. But let's leave it as is this time.

@austindrenski
Copy link
Contributor

@YohDeadfall When I read this earlier, I thought there might be some overlap, but I was indeed mistaken. Once #605 is merged, I'll take a look at this one separately.

@roji
Copy link
Member

roji commented Nov 14, 2018

I'm going to add this to 2.2.0 for now, hoping we can fix it by the time we release.

@roji roji added this to the 2.2.0 milestone Nov 14, 2018
@roji roji modified the milestones: 2.2.0, 2.2.1 Dec 4, 2018
@austindrenski austindrenski self-assigned this Dec 5, 2018
@austindrenski
Copy link
Contributor

austindrenski commented Dec 5, 2018

FYI starting to look into this now.

Notes

@austindrenski
Copy link
Contributor

austindrenski commented Dec 5, 2018

Actually, I can't reproduce this in the test suite. The 2.2 release notes do reference changes to owned type behavior, so it's possible that this was simply resolved upstream.

@YohDeadfall Here's the setup I used to try and reproduce this. Does the configuration look right? Are you still able to reproduce this locally?

[Fact]
public void Where_with_owned_type()
{
    using (var ctx = Fixture.CreateContext())
    {
        var _ = ctx.SomeEntities.Single(e => e.OwnedTypeWithEnum.MappedEnum == MappedEnum.Happy);

        AssertContainsInSql("WHERE e.\"OwnedTypeWithEnum_MappedEnum\" = 'happy'::test.mapped_enum");
    }
}
public class SomeEnumEntity
{
    public int Id { get; set; }
    public MappedEnum MappedEnum { get; set; }
    public UnmappedEnum UnmappedEnum { get; set; }
    public InferredEnum InferredEnum { get; set; }
    public SchemaQualifiedEnum SchemaQualifiedEnum { get; set; }
    public int EnumValue { get; set; }

    public OwnedTypeWithEnum OwnedTypeWithEnum { get; set; }
}

public class OwnedTypeWithEnum
{
    public MappedEnum MappedEnum { get; set; }
    public UnmappedEnum UnmappedEnum { get; set; }
    public InferredEnum InferredEnum { get; set; }
    public SchemaQualifiedEnum SchemaQualifiedEnum { get; set; }
    public int EnumValue { get; set; }
}
protected override void OnModelCreating(ModelBuilder builder)
{
    builder.ForNpgsqlHasEnum("mapped_enum", new[] { "happy", "sad" })
           .ForNpgsqlHasEnum<InferredEnum>()
           .HasDefaultSchema("test")
           .ForNpgsqlHasEnum<SchemaQualifiedEnum>();

    builder.Entity<SomeEnumEntity>().OwnsOne(x => x.OwnedTypeWithEnum);
}

Note that I tested this in a branch following #685, so the schema handling may look different from the current dev branch.

@YohDeadfall
Copy link
Contributor Author

We have moved out from EF for the current project (: Will check it when I have half an hour to spare.

@roji
Copy link
Member

roji commented Dec 6, 2018

@YohDeadfall hope it's nothing bad with EF :) Do you want to continue being active and reviewing EF stuff or only Npgsql?

@YohDeadfall
Copy link
Contributor Author

It's very limited for our goals and too slow in comparison with pure Npgsql and SQL, but we will continue to use it for migrations only which are written in plain SQL (: Yes, I want to work on EF too, but currently I'm busy with the presentation I mentioned in person. It covers npgsql/npgsql#2180.

@roji
Copy link
Member

roji commented Dec 6, 2018

OK, great - we can also use your work to write that page on migrating from MSSQL. Good luck with the presentation!

@YohDeadfall
Copy link
Contributor Author

YohDeadfall commented Dec 12, 2018

Looks like I've omitted some part that triggers the problem or most likely had an issue in the application... Closing as I can't reproduce it too. Thanks for taking a look!

@YohDeadfall YohDeadfall removed this from the 2.2.1 milestone Dec 12, 2018
@YohDeadfall YohDeadfall removed the bug Something isn't working label Dec 12, 2018
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