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

Table splitting isn't working with nonnullable reference types. #18574

Closed
bperc2 opened this issue Oct 24, 2019 · 4 comments
Closed

Table splitting isn't working with nonnullable reference types. #18574

bperc2 opened this issue Oct 24, 2019 · 4 comments

Comments

@bperc2
Copy link

bperc2 commented Oct 24, 2019

With Nullable Reference Types turned on, Entity Framework Core is unable to map two nonnullable reference types to the same column of a table.

Steps to reproduce

To reproduce this issue, I modified the table splitting example of the EF Core documentation: https://docs.microsoft.com/en-us/ef/core/modeling/table-splitting

    public class Order
    {
        public int Id { get; set; }
        public string Category { get; set; }
        public OrderStatus? Status { get; set; }
        public DetailedOrder DetailedOrder { get; set; }
    }
    public class DetailedOrder
    {
        public int Id { get; set; }
        public string Category { get; set; }
        public OrderStatus? Status { get; set; }
        public string BillingAddress { get; set; }
        public string ShippingAddress { get; set; }
        public byte[] Version { get; set; }
    }
    modelBuilder.Entity<DetailedOrder>(dob =>
    {
        dob.ToTable("Orders");
        dob.Property(o => o.Category).HasColumnName("Category");
        dob.Property(o => o.Status).HasColumnName("Status");
    });

    modelBuilder.Entity<Order>(ob =>
    {
        ob.ToTable("Orders");
        ob.Property(o => o.Category).HasColumnName("Category");
        ob.Property(o => o.Status).HasColumnName("Status");
        ob.HasOne(o => o.DetailedOrder).WithOne()
            .HasForeignKey<DetailedOrder>(o => o.Id);
    });

With this setup, adding a migration will fail with the following error message:

'DetailedOrder.Category' and 'Order.Category' are both mapped to column 'Category' in 'Orders' but are configured with different nullability.

Further technical details

EF Core version: 3.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.3

@AndriySvyryd
Copy link
Member

@bperc2 This is not supported yet.

Duplicate of #12100

@flcdrg
Copy link

flcdrg commented Nov 27, 2019

This is a regression from 2.2 where this did work.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
@sbojarczak
Copy link

I have the same issue again. I've checked #12100, but making Navigation required didn't help. Is it supported or still not? I'm confused

@ajcvickers
Copy link
Member

@sbojarczak Please open a new issue and attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

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

No branches or pull requests

5 participants