实体框架与实体名称匹配时在属性名称后附加“ 1” [英] Entity Framework appending '1' to property name when it matches entity name

查看:68
本文介绍了实体框架与实体名称匹配时在属性名称后附加“ 1”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Entity Framework 4.0版使用数据库优先方法创建模型。在数据库中,有许多表包含与其父表相同名称的列。

I am using Entity Framework version 4.0 to create a model using the database first approach. In the database, there's a number of tables that contain columns named the same as their parent table.

例如,我们有


  • 表State的列为State和StateName

  • 表带有列状态和描述的状态

问题是,当这些表之一是导入EF模型后,这些列的属性名称将被映射为在其末尾附加一个 1。

The issue is that when one of these tables is imported into the EF model, the property names that those columns get mapped to get a '1' appended to the end of them.

所以我最终得到了


  • 具有属性State1和StateName的实体状态

  • 具有属性Status1和描述的实体状态

当我尝试删除结尾处的 1时,出现一条消息,提示名称Status在这种情况下不能重复。请选择其他名称。

When I attempt to remove the '1' at the end, I get a message saying "The name Status cannot be duplicated in this context. Please choose another name."

我有办法让我的属性保留其名称吗?或者这是框架中有文件证明的限制?

Is there a way for me to have my properties keep their names or is this a documented limitation in the framework?

推荐答案

您的班级中不能有一个像班级那样命名的成员。

You can't have a member in your class which is named like your class is.

示例:

class Test
{
    // Invalid
    int Test;

    // Invalid
    public int Test {get; set; }

    // OK
    int Test1; 
}

这篇关于实体框架与实体名称匹配时在属性名称后附加“ 1”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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