PREFACE: I think this is a bug in the EF code base but I'm open to suggestions for a change in my model as well.
The Error:
When EF Code First attempts to build my model, I get the exception: The operation failed because an index or statistics with name 'IX_LotInventoryItemTypeId_ProductId' already exists on table 'dbo.Inventory'.
The Data Models:
I am developing a custom inventory system which includes models:
The inventory tree is utilizing TPT inheritance such that InventoryBase => dbo.Inventory, ChileInventory => dbo.ChileInventory, PackagingInventory => dbo.PackagingInventory
The product tree is utilizing TPC inheritance. All derived product types contain the same primary key properties as the base class.
It appears that, since the InventoryBase class defines navigation properties to the derivatives of ProductBase EF is trying to create multiple indexes for the foreign key properties. Below are diagrams of the inventory and product class trees. Does anyone
see something I'm missing? Do you see a flaw in the structure of my models or does this appear to actually be a EF bug?
Ok, so because ProductId is defined on the InventoryBase class, and because I'm using TPT inheritance in the inventory class tree, the derived inventory types don't get a ProductId column in the database. This means that the Inventory table must define the
foreign key relationships for all derived types rather than the derived inventory type definine a relationship to it's specific derived product type. Following this?
vinneyk
Member
139 Points
92 Posts
EF Code First generating duplicate index names for base class
Aug 03, 2012 05:41 PM|LINK
PREFACE: I think this is a bug in the EF code base but I'm open to suggestions for a change in my model as well.
The Error:
When EF Code First attempts to build my model, I get the exception: The operation failed because an index or statistics with name 'IX_LotInventoryItemTypeId_ProductId' already exists on table 'dbo.Inventory'.
The Data Models:
I am developing a custom inventory system which includes models:
InventoryBase, ChileInventory, PackagingInventory
ProductBase, ChileProduct, PackagingProduct
The inventory tree is utilizing TPT inheritance such that InventoryBase => dbo.Inventory, ChileInventory => dbo.ChileInventory, PackagingInventory => dbo.PackagingInventory
The product tree is utilizing TPC inheritance. All derived product types contain the same primary key properties as the base class.
It appears that, since the InventoryBase class defines navigation properties to the derivatives of ProductBase EF is trying to create multiple indexes for the foreign key properties. Below are diagrams of the inventory and product class trees. Does anyone see something I'm missing? Do you see a flaw in the structure of my models or does this appear to actually be a EF bug?
Thanks!
inheritance bug codefirst
vinneyk
Member
139 Points
92 Posts
Re: EF Code First generating duplicate index names for base class
Aug 03, 2012 05:48 PM|LINK
Ok, so because ProductId is defined on the InventoryBase class, and because I'm using TPT inheritance in the inventory class tree, the derived inventory types don't get a ProductId column in the database. This means that the Inventory table must define the foreign key relationships for all derived types rather than the derived inventory type definine a relationship to it's specific derived product type. Following this?
vinneyk
Member
139 Points
92 Posts
Re: EF Code First generating duplicate index names for base class
Aug 03, 2012 07:02 PM|LINK
Here's what I want to generate:
And this is what I'm getting:
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: EF Code First generating duplicate index names for base class
Aug 05, 2012 01:52 AM|LINK
Hello,
I cannot see the images……Would you mind showing us your full codes of Code-first?
Reguards!
inheritance bug codefirst