Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 05, 2012 01:52 AM by Decker Dong - MSFT
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.
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?
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?
Aug 03, 2012 07:02 PM|LINK
Here's what I want to generate:
And this is what I'm getting:
Aug 05, 2012 01:52 AM|LINK
I cannot see the images……Would you mind showing us your full codes of Code-first？