none
.net dbml generator bug RRS feed

  • Question

  • If your database contains a table with a column that is called 'string' , the .NET dbml generator fails. It fails due to each partial class that is generated contains the static field 'emptyChangingEventArgs' of type 'PropertyChangingEventArgs' , this is set in the following manner:

    private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

    As you can see from the above, String.Empty is passed into the constructor, this is an issue (for some reason) due to the fact that this tries to access the private field 'String' and discovers it is not static and errors with the following:

    Error 30  A field initializer cannot reference the non-static field, method, or property 'ConsoleApplication1.Methods.String.get'.

    Fix1: Replace String.Empty in the constructor argument with System.String.Empty.

    More preferably due to languages like F# using the dbml generation automatically: Fix2 Modify column name to not be 'string'.

    Here is the section of the DBML in XML format:

    <Table Name="dbo.methods" Member="Methods">
        <Type Name="Methods">
          <Column Name="Id" Type="System.Int32" DbType="Int NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
          <Column Name="name" Member="Name" Type="System.String" DbType="NVarChar(MAX) NOT NULL" CanBeNull="false" UpdateCheck="Never" />
          <Column Name="call" Member="Call" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
          <Column Name="field" Member="Field" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
          <Column Name="string" Member="String" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
          <Column Name="hash" Member="Hash" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
        </Type>
      </Table>
    • Moved by Fred BaoModerator Monday, November 10, 2014 5:18 AM Move to a more appropriate forum
    Saturday, November 8, 2014 12:31 AM

Answers

  • Hello fasd23,

    Thanks for sharing this feedback and providing correspondent solutions for us. I would help quote your two fixs to a separate post so that it will be very beneficial for other community members who have similar questions.

    Solutions for this issue:

    Fix1: Replace String.Empty in the constructor argument with System.String.Empty. More preferably due to languages like F# using the dbml generation automatically:

    Fix2 Modify column name to not be 'string'.

    In my opinion, i would recommend the second one.

    Regards.


    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, November 10, 2014 5:38 AM
    Moderator