如何命名与数据库的第一种方法外键 [英] How to name foreign keys with database first approach

查看:158
本文介绍了如何命名与数据库的第一种方法外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法更改与实体框架的命名约定

Is there a way to change the naming convention with Entity Framework?

例如:

我有表2

Planification
--------------
creator_id <fk>
guest_id <fk>


Profile
--------------
profile_id <pk>



creator_id guest_id 是对 PROFILE_ID

在默认情况下,实体将产生planification类像这样

by default, entity would generate a planification class like this

public string guest_id { get; set; }
public string creator_id { get; set; }

public virtual Profile Profile { get; set; }
public virtual Profile Profile1 { get; set; }



我宁愿比简介和 Profile1的访客

有没有办法来改变命名规则,因为我觉得很内疚让它这样。

Is there a way to change the naming convention because I feel really guilty letting it like this.

推荐答案

在您的EDMX,您可以通过点击属性和改变名称重命名导航属性。

In your edmx you can rename the nav properties by clicking on the property and changing the Name.

请注意,如果删除该表,并从数据库建立一遍你必须给它的命名EDMX

Note that if you delete the table and build it from the database again you will have to rename it in the edmx.

如果你被这种充分恼火。为了得到一个办法解决它,而不是使用部分类,给出了一个名称为默认命名两个属性。

If you are sufficiently annoyed by this. A way to get around it is to instead use a partial class with a property that gives a name to the default-named property.

public partial class Planification
{
    public Profile Creator 
    { 
        get{ return this.Profile1; }
        set{
            this.Profile1 = value;
        } 
    }

    public Profile Guest 
    { 
        get{ return this.Profile; }
        set{
            this.Profile = value;
        } 
    }
}

这篇关于如何命名与数据库的第一种方法外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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