如何停止EDMX生成器更改列名称

编程入门 行业动态 更新时间:2024-10-26 13:30:19
本文介绍了如何停止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生成器更改列名称

本文发布于:2023-11-12 00:57:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580044.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:生成器   名称   EDMX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!