如何停止EDMX生成器更改列名称 [英] How to stop the EDMX generator from changing columns names

查看:90
本文介绍了如何停止EDMX生成器更改列名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果表的列名与表名称相同,则EDMX生成器将列名后缀为1。例如:将测试更改为以下示例中的Test1。

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表定义:

SQL Server Table definition:

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

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

EF创建模型:

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

这将导致SqlQueries抛出错误数据读取器与指定的AdventureWorksModel.Test不兼容。类型Test1的成员没有一个相应的列e数据读取器具有相同的名称。

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."

为什么DbContext生成器修改列名称? ObjectContext生成器将它们单独留下。

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

我们如何解决这个问题?我们无法控制DB模式。

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

推荐答案

我们无法更改此行为。 EDMX生成器更改列名称,因为C#编译器不会让您拥有同名成员的类。请参阅 MSDN论坛

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

这篇关于如何停止EDMX生成器更改列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆