How to stop the EDMX generator from changing columns names

£可爱£侵袭症+ 提交于 2020-01-07 02:31:06

问题


If a table has column names that are the same as the table name the EDMX Generator suffixes the column name with a "1". Ex: Changing Test to Test1 in the sample below.

SQL Server Table definition:

CREATE TABLE [dbo].[Test]( [Test] nchar NOT NULL, [ColumnsTwo] nchar NULL,

EF Model created:

     <EntitySetMapping Name="Test">
        <EntityTypeMapping TypeName="AdventureWorksModel.Test">
          <MappingFragment StoreEntitySet="Test">
            <ScalarProperty Name="ColumnsTwo" ColumnName="ColumnsTwo" />
            <ScalarProperty Name="Test1" ColumnName="Test" />
          </MappingFragment>
        </EntityTypeMapping>
      </EntitySetMapping>
    </EntityContainerMapping>

This causes SqlQueries to throw the error "The data reader is incompatible with the specified 'AdventureWorksModel.Test'. A member of the type, 'Test1', does not have a corresponding column in the data reader with the same name."

Why does the DbContext generator modify the column name? The ObjectContext generator left them alone.

How can we fix this? We have no control over the DB schema.


回答1:


We cannot change this behavior. The EDMX generator changes column names, because the C# compiler will not let you have a class with a member of the same name. See MSDN Forum



来源:https://stackoverflow.com/questions/12732114/how-to-stop-the-edmx-generator-from-changing-columns-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!