为什么当我选择从数据库更新我的 .edmx 文件时 Model.tt 类不会得到更新

joh*_* Gu 0 entity-framework edmx edmx-designer entity-framework-5

我正在开发一个 asp.net mvc-4 web 应用程序。我正在使用实体框架 5。我使用 EF 映射了我的数据库表。

现在我曾经在我的 .tt 文件夹中有以下模型类:-

public partial class CustomAsset
    {
        public string CustomerName { get; set; }
        public int CustomTypeID { get; set; }
        public string Description { get; set; }
        public int ID { get; set; }
        public int Quantity { get; set; }


        public virtual CustomAssetType CustomAssetType { get; set; }

    }
Run Code Online (Sandbox Code Playgroud)

现在在名为“customAsset”的数据库表中,我删除了该CustomerName列。我添加了两列,其中一列是另一个表的外键。然后我打开我的 .edmx 文件,我右键单击,然后我选择从数据库更新模型,在那里我选择相关表并单击更新。现在 .edmx 文件中的模型正确地获得了新的列/关系,如下所示:-

在此处输入图片说明

但我相关的 .tt 类仍在引用旧列。我期待我的 .tt 模型类如下:-

public partial class CustomAsset
    {
        //public string CustomerName { get; set; }
        public int CustomTypeID { get; set; }
        public string Description { get; set; }
        public int ID { get; set; }
        public int Quantity { get; set; }
        public int? CustomerID { get; set; }
        public int? RackID { get; set; }

        public virtual CustomAssetType CustomAssetType { get; set; }
        public virtual Rack Rack { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

所以不确定如何在我更新 .edmx 文件时强制我的 .tt 类更新?如果我手动修改相关的 .tt 类以获得新的列/关系,是否有任何问题?

BSG*_*BSG 5

1.Build the project after updating EDMX file.

2.Right click your .tt file in solution explorer.

3.Select "Run Custom Tool" option.

This will update the .tt file.
Run Code Online (Sandbox Code Playgroud)