none
.net dbml generation issue

    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>

    Friday, November 07, 2014 12:23 AM

Answers