I am trying to implement TPH recursive relationship on one of the concrete types using Entity Framework 5 and Database first approach. I have conceptual model, and table structure like this:
Also, i have recursive relationship like this in my database table.
ALTER TABLE [dbo].[BaseType]
WITH CHECK ADD CONSTRAINT [FK_BaseType_DerivedType]
FOREIGN KEY([Derived1RecursiveId])
REFERENCES [dbo].[BaseType] ([Id])
When i update model with this relation i get diagram like this:
My question is:
How can i implement a recursive relationship in a database so that when model is updated from database (refreshed), recursive relationship is set on DerivedType1?
It is not possible for the EF model to automatically deduce that the Derived1RecourseiveId is part of the Derived1 class. But you can move the association in your edmx file manually. Just move the foreign key column, delete the association on your base table and recreate it on the derived. Once moved it will stay in your derived type even if you do a model refresh.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With