question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

One-to-one relationship swaps principal/dependent moving from 1.1 to 2.0

See original GitHub issue

The model below makes one end principal in 1.1 and the other end principal in 2.0.

public class ProductsTable
 {
     [Key]
     public int id { get; set; }
     public virtual ProductsInventoryTable ProductsInventory { get; set; }
 }

 public class ProductsInventoryTable
 {
     [Key]
     public int id { get; set; }
     public virtual ProductsTable Product { get; set; }
 }

 public class TestContext : DbContext
 {
     public DbSet<ProductsTable> ProductsTable { get; set; }
     public DbSet<ProductsInventoryTable> ProductsInventoryTable { get; set; }

     protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
         => optionsBuilder.UseSqlServer(
             @"Server=(localdb)\mssqllocaldb;Database=Test;Trusted_Connection=True;ConnectRetryCount=0");
 }

1.1.2:

EntityType: ProductsInventoryTable
  Properties: 
    id (int) Required PK ReadOnlyAfterSave RequiresValueGenerator ValueGenerated.OnAdd 0 0 0 -1 0
  Navigations: 
    Product (<Product>k__BackingField, ProductsTable) ToDependent ProductsTable Inverse: ProductsInventory 0 -1 1 -1 -1
  Keys: 
    id PK
EntityType: ProductsTable
  Properties: 
    id (int) Required PK FK ReadOnlyAfterSave 0 0 0 -1 0
  Navigations: 
    ProductsInventory (<ProductsInventory>k__BackingField, ProductsInventoryTable) ToPrincipal ProductsInventoryTable Inverse: Product 0 -1 1 -1 -1
  Keys: 
    id PK
  Foreign keys: 
    id -> ProductsInventoryTable.id Unique ToDependent: Product ToPrincipal: ProductsInventory

2.0:

EntityType: ProductsInventoryTable
  Properties: 
    id (int) Required PK FK AfterSave:Throw 0 0 0 -1 0
  Navigations: 
    Product (<Product>k__BackingField, ProductsTable) ToPrincipal ProductsTable Inverse: ProductsInventory 0 -1 1 -1 -1
  Keys: 
    id PK
  Foreign keys: 
    ProductsInventoryTable {'id'} -> ProductsTable {'id'} Unique ToDependent: ProductsInventory ToPrincipal: Product
EntityType: ProductsTable
  Properties: 
    id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd 0 0 0 -1 0
  Navigations: 
    ProductsInventory (<ProductsInventory>k__BackingField, ProductsInventoryTable) ToDependent ProductsInventoryTable Inverse: Product 0 -1 1 -1 -1
  Keys: 
    id PK

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
AndriySvyrydcommented, Aug 17, 2017

This should throw in validation as ambiguous principal end

0reactions
ajcvickerscommented, Aug 23, 2017

Triage decision: we will correctly detect this as ambiguous in 2.1 and throw a validation exception. Given that we are going to do this in 2.1 and we think that hitting this will not be super-common in 2.0, we are not going to patch anything.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Capita plc Annual Report 2018
Pages 1–98 of this Annual Report comprise a report of the Directors that has been drawn up and presented in accordance with English...
Read more >
Entity Framework Core in Action [1 ed.] 161729456X, 978- ...
Entity Framework Core in Action covers all the features of EF Core 2.0, ... Figure 2.1 The one-to-one relationship between a Book and...
Read more >
Capita plc Annual Report 2021
Cautionary statement. The directors present the Annual Report for the year ended. 31 December 2021, which includes the strategic report,.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found