LINQ to SQL : Duplicate Columns RRS feed

  • Question

  • Hi

    I have 2 tables as following.

    Table 1: Team ,

    Columns : TeamID , TeamName

    Table 2 : Match

    Columns : MatchID , Team1, Team2 , Winner

    Relation : Match.Team1=>Team.TeamID , Match.Team2=>Team.TeamID , Match.Winner =>Team.TeamID

    When I add this table to my LINQ to SQL DBML File, I see that while the relations are displayed as desired in the file, but when i use it in class files,  i see 2 additional columns in the Match Table. ( Team1 , Team2 , Winner , Team3, Team4)

    Can any one please tell how should i get rid of it ? I guess it is the relation that is being shown ?

    Anu Viswan :

    Friday, July 4, 2014 2:55 PM


  • Hello,

    >>i see 2 additional columns in the Match Table. ( Team1 , Team2 , Winner , Team3, Team4)

    What is the type of the Team3 amd Team4 object? Is it the Team type? Because I create the tables with the schema from your description, after I drop the two tables to the dbml, it creates two addition navigation properties as:

    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Team_Match1", Storage="_Team3", ThisKey="Team2", OtherKey="TeamID", IsForeignKey=true)]
                  public Team Team3
                  [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Team_Match2", Storage="_Team4", ThisKey="Winner", OtherKey="TeamID", IsForeignKey=true)]
                  public Team Team4

    Is it that you mean? If it is, this is by designed, the two addition properties are navigation properties since you have define three foreign keys in the sub table which is mapped to the same column in master table.

    The Team3 property is for Team2 foreign key, the Team4 property is for Winner foreign key as it describes clearly in th  AssociationAttribute.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, July 7, 2014 2:13 AM