none
Inverted Tree, Generated Code Problem RRS feed

  • General discussion

  •  

    Hello there,

     

    Suppose we have a schema that contains an Inverted Tree structure. In SQL terminology that would be:

    Code Snippet

    IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id('FK_Node_Node') AND OBJECTPROPERTY(id, 'IsForeignKey') = 1)
    ALTER TABLE Node DROP CONSTRAINT FK_Node_Node
    ;


    IF EXISTS (SELECT * FROM dbo.SYSOBJECTS WHERE id = object_id('Node') AND  OBJECTPROPERTY(id, 'IsUserTable') = 1)
    DROP TABLE Node
    ;


    CREATE TABLE Node (
     NodeID int NOT NULL,
     ParentID int
    )
    ;


    ALTER TABLE Node ADD CONSTRAINT PK_Node
     PRIMARY KEY CLUSTERED (NodeID)
    ;

     

    ALTER TABLE Node ADD CONSTRAINT FK_Node_Node
     FOREIGN KEY (ParentID) REFERENCES Node (NodeID)
    ;

     

     

    The LINQ to SQL does not generate properly the Parent property. Instead it generates a Node1 property. Sample code can be found here.

    Wednesday, May 28, 2008 7:34 PM

All replies

  • I gather that you are using the Designer?

     

    To change the name of the generated property, select the association object on the Designer surface, right-click to display the context menu, and select 'Properties'.

     

    In the Properties window, expand the 'Parent' group and change the name to whatever you like.

     

    Hope that answers your question.

     

    --Samir

     

    Wednesday, May 28, 2008 7:52 PM
  •  

    Thank you.
    Wednesday, May 28, 2008 8:02 PM