Reputation: 2586
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.
Upvotes: 0
Views: 636
Reputation: 2586
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
Upvotes: 1