none
LINQ designer deletes column automatically RRS feed

  • Question

  • Hello,

    I used the LINQ to SQL designer, dragging a table onto the designer, when I noticed that a column went missing. It appears that the designer automatically deletes columns that have the same name as their containing table.

    Just an interesting observation. I inherited the database from a legacy system in which the DBA apparently didn't care about potential ambiguities. I'm off to rename the column now. :)

    Cheers,
     Tess
    Tess_H
    Wednesday, September 30, 2009 8:15 PM

Answers

  • Hi Tess_H,

     

    Welcome to LINQ to SQL forum!

     

    Thank you very much for reporting this issue.  However, I did not find any related known issues in our internal database.  Also I cannot reproduce this problem.  I created a table named MyColumn which has two columns named MyColumnID and MyColumn.  After a dragging the table into the O/R designer, the column MyColumn is renamed to MyColumn1.  I am using C# and the property declaration is: (The property MyColumn1 is mapped to the column MyColumn)

    ===============================================================================
                    [Column(Name="MyColumn", Storage="_MyColumn1", DbType="NVarChar(50)")]

                    public string MyColumn1

                    {

                            get

                            {

                                    return this._MyColumn1;

                            }

                            set

                            {

                                    if ((this._MyColumn1 != value))

                                    {

                                            this.OnMyColumn1Changing(value);

                                            this.SendPropertyChanging();

                                            this._MyColumn1 = value;

                                            this.SendPropertyChanged("MyColumn1");

                                            this.OnMyColumn1Changed();

                                    }

                            }

                    }
    ===============================================================================

     

    Due to C# language feature, we cannot have a member with the same name as its enclosing type.  For detail, please see http://msdn.microsoft.com/en-us/library/hdhfk2xk.aspx.   However, in VB.NET it is allowed to have such members.  So the corresponding VB.NET codes are fine:

    ===============================================================================
            <Column(Storage:="_MyColumn", DbType:="NVarChar(50)")>  _

            Public Property MyColumn() As String

                    Get

                            Return Me._MyColumn

                    End Get

                    Set

                            If (String.Equals(Me._MyColumn, value) = false) Then

                                    Me.OnMyColumnChanging(value)

                                    Me.SendPropertyChanging

                                    Me._MyColumn = value

                                    Me.SendPropertyChanged("MyColumn")

                                    Me.OnMyColumnChanged

                            End If

                    End Set

            End Property
    ===============================================================================

    Tess_H, do you inherit some table in the O/R designer or just dragging a table from the server?   Could you please tell me the detailed steps to reproduce this issue?   Besides, I am using Visual Studio 2008 SP1, please make sure to install the latest service pack of Visual Studio 2008.  If I can reproduce the problem as you have described, I will open a ticket on the Microsoft Connect to report this issue to the product team. 

     

    Thanks again and have a nice day!

     

     

    Best Regards,
    Lingzhi Sun


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Tess_H Thursday, October 1, 2009 3:18 PM
    Thursday, October 1, 2009 1:51 AM
    Moderator

All replies

  • Hi Tess_H,

     

    Welcome to LINQ to SQL forum!

     

    Thank you very much for reporting this issue.  However, I did not find any related known issues in our internal database.  Also I cannot reproduce this problem.  I created a table named MyColumn which has two columns named MyColumnID and MyColumn.  After a dragging the table into the O/R designer, the column MyColumn is renamed to MyColumn1.  I am using C# and the property declaration is: (The property MyColumn1 is mapped to the column MyColumn)

    ===============================================================================
                    [Column(Name="MyColumn", Storage="_MyColumn1", DbType="NVarChar(50)")]

                    public string MyColumn1

                    {

                            get

                            {

                                    return this._MyColumn1;

                            }

                            set

                            {

                                    if ((this._MyColumn1 != value))

                                    {

                                            this.OnMyColumn1Changing(value);

                                            this.SendPropertyChanging();

                                            this._MyColumn1 = value;

                                            this.SendPropertyChanged("MyColumn1");

                                            this.OnMyColumn1Changed();

                                    }

                            }

                    }
    ===============================================================================

     

    Due to C# language feature, we cannot have a member with the same name as its enclosing type.  For detail, please see http://msdn.microsoft.com/en-us/library/hdhfk2xk.aspx.   However, in VB.NET it is allowed to have such members.  So the corresponding VB.NET codes are fine:

    ===============================================================================
            <Column(Storage:="_MyColumn", DbType:="NVarChar(50)")>  _

            Public Property MyColumn() As String

                    Get

                            Return Me._MyColumn

                    End Get

                    Set

                            If (String.Equals(Me._MyColumn, value) = false) Then

                                    Me.OnMyColumnChanging(value)

                                    Me.SendPropertyChanging

                                    Me._MyColumn = value

                                    Me.SendPropertyChanged("MyColumn")

                                    Me.OnMyColumnChanged

                            End If

                    End Set

            End Property
    ===============================================================================

    Tess_H, do you inherit some table in the O/R designer or just dragging a table from the server?   Could you please tell me the detailed steps to reproduce this issue?   Besides, I am using Visual Studio 2008 SP1, please make sure to install the latest service pack of Visual Studio 2008.  If I can reproduce the problem as you have described, I will open a ticket on the Microsoft Connect to report this issue to the product team. 

     

    Thanks again and have a nice day!

     

     

    Best Regards,
    Lingzhi Sun


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Tess_H Thursday, October 1, 2009 3:18 PM
    Thursday, October 1, 2009 1:51 AM
    Moderator
  • Hello, Linggzhi Sun, and thanks for your response.

    My mistake: the column is renamed with the "1" added at the end! There are many other columns in the table with ambiguous names; even the DBML designer.cs is complaining ("This member is defined more than once."). But I'm able to work with it as is.

    I'll pay more attention to the designer column mapping in the future. Thanks for sharing your insight.

    Tess
    Tess_H
    Thursday, October 1, 2009 3:18 PM