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

Mapping an owned type to a different table produces an error on SqlServer #17454

Closed
AndriySvyryd opened this issue Aug 27, 2019 · 0 comments · Fixed by #17458
Closed

Mapping an owned type to a different table produces an error on SqlServer #17454

AndriySvyryd opened this issue Aug 27, 2019 · 0 comments · Fixed by #17458
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported regression type-bug
Milestone

Comments

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Aug 27, 2019

The PK on the owned type is being erroneously marked as ValueGenerated.OnAdd

Originally reported in #17448

Exception message:Microsoft.Data.SqlClient.SqlException: 'Cascading foreign key 'FK_OrderDetails_DetailedOrders_OrderId' cannot be created where the referencing column 'OrderDetails.OrderId' is an identity column.
Could not create constraint or index. See previous errors.'

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<DetailedOrder>().OwnsOne(p => p.OrderDetails, od =>
    {
        od.ToTable("OrderDetails");
    });
}
public class DetailedOrder
{
    public int Id { get; set; }
    public OrderDetails OrderDetails { get; set; }
}

public class OrderDetails
{
    public DetailedOrder Order { get; set; }
    public string BillingAddress { get; set; }
    public string ShippingAddress { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported regression type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants