One-to-one relationship swaps principal/dependent moving from 1.1 to 2.0
See original GitHub issueThe 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:
- Created 6 years ago
- Comments:11 (11 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This should throw in validation as ambiguous principal end
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.