0

我正在开发一个 asp.net mvc-4 web 应用程序。我正在使用 Entity Framework 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; }

    }

现在在名为“customAsset”的数据库表中,我删除了该CustomerName列。我添加了两列,其中一列是另一个表的外键。然后我打开我的 .edmx 文件我右键单击,然后我选择从数据库中更新模型,在那里我选择 realted 表并单击更新。现在 .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; }
    }

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

4

1 回答 1

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.
于 2016-05-04T13:14:56.927 回答