CodeSmith Community
Your Code. Your Way. Faster!

Foreign Key Contraints, deletion of parent

Latest post 03-13-2008 3:28 PM by CitizenBane. 1 replies.
  • 03-13-2008 9:30 AM

    • CitizenBane
    • Top 50 Contributor
    • Joined on 10-30-2007
    • Grand Rapids, MI
    • Posts 94
    • Points 1,740

    Foreign Key Contraints, deletion of parent

    I want to prevent the deletion of the parent, and my primary/foreign key constraints do this for me.  Unfortunately, I have no way of knowing if the parent is deleteable or not, so if a user clicks on the "Delete" button, for example, they would get a nasty error message. 

    I would love it if there was some sort of parameter in my entities that would tell me if the entity is deleteable or not, based on a foreign key constraint or some other set of rules that I could define.   Perhaps an IsDeleteable property?

    Would this be too much, or overkill to add?  How have you approached this?

    Thanks.

     

    I'm outside ur box, shiftin' ur paradigm.
    • Post Points: 5
  • 03-13-2008 3:28 PM In reply to

    • CitizenBane
    • Top 50 Contributor
    • Joined on 10-30-2007
    • Grand Rapids, MI
    • Posts 94
    • Points 1,740

    Re: Foreign Key Contraints, deletion of parent

    I'm doing a little research on how to find the dependencies of my tables and whether or not a row is deleteable, and I found this handy blog entry:
    http://blog.sqlauthority.com/2006/11/01/sql-server-query-to-display-foreign-key-relationships-and-name-of-the-constraint-for-each-table-in-database/

    More info on how to find if a record is indeed deleteable:

    http://1bit.us/ViewArticle.aspx?id=9d947d58-ed71-49d9-b712-6bf051e8e3ff

    Basically, you create a table called "Relationships" which would store some basic info about the tables and their dependencies.

    Then, you create a stored proc called "CanDeleteQueries" that will look up the table and primary key of the entity in question, and it returns a count of how many dependencies it has.

    If the count > 0, you know you cannot delete it.

    Our IsDeleteable property would look something like this:

    public bool IsDeleteable()
    {
       get { return Common.CanDelete(this.TableName, this.EntityId); }

    }

     

    What do you think?

    I'm outside ur box, shiftin' ur paradigm.
    • Post Points: 5
Page 1 of 1 (2 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems