locked
Self Referencing tables issues in Entity FrameWork RRS feed

  • Question

  • I using asp.net mvc 5 Entity FrameWork 6 with  lots of self referencing keys in the SQL Server database. I want to find out if it is a good idea to use these self referencing keys and if not what is the best approach


    Ebenezer

    selfRef

    • Edited by denkyira Wednesday, June 17, 2020 10:52 PM Edit English
    Wednesday, June 17, 2020 6:50 PM

Answers

  • Hi denkyira,
    Self-referencing table in entity framework is used to store some hierarchical data, and a self referencing table is a table where the primary key (PK) of a table is also known a foreign key.
    So it's a good idea if the relationship is actually hierarchical, and not a network relationship.
    Like other methods, this method has its advantages and disadvantages. This design simplifies the maintenance of the hierarchy. However, the query is not easy.
    You usually need to use recursive query on CTE, the query efficiency is reduced.
    There is more discussion about  self referencing table in this thread you can refer to.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by John Boncek Thursday, June 18, 2020 2:39 PM
    • Marked as answer by denkyira Thursday, June 18, 2020 3:09 PM
    Thursday, June 18, 2020 3:12 AM