简体   繁体   English

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

[英]why the Model.tt classes will not get updated when i chose to update my .edmx file from database

i am working on an asp.net mvc-4 web application . 我正在asp.net mvc-4 Web应用程序上工作。 and i am using Entity Framework 5. where i mapped my database tables using EF. 我正在使用Entity Framework5。在这里,我使用EF映射了数据库表。

now i use to have the following model class inside my .tt folder:- 现在我曾经在我的.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; }

    }

now inside my DB table named "customAsset" i remove the CustomerName column. 现在,在名为“ customAsset”的数据库表中,删除了CustomerName列。 and i added two columns one of them is a foreign key to another table. 我添加了两列,其中一列是另一个表的外键。 then i open my .edmx file i right-click , then i chose to update model from database, where i select the realted table and click on update. 然后,我右键单击打开.edmx文件,然后选择从数据库更新模型,在该数据库中选择实际表并单击“更新”。 now the model inside the .edmx file got the new columns/relation correctly as follow:- 现在,.edmx文件中的模型正确地获得了新的列/关系,如下所示:

在此处输入图片说明

but my related .tt class is still referencing the old columns. 但我的相关.tt类仍在引用旧列。 i was expecting my .tt model class to be as follow:- 我期望我的.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; }
    }

so not sure how i can force my .tt classes to get updated , when i update the .edmx file ? 所以不确定在更新.edmx文件时如何强制更新.tt类? and is there any problem if i manually modify the related .tt classes to get the new columns/ relation ? 如果我手动修改相关的.tt类以获取新的列/关系,是否有任何问题?

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .edmx实体文件中的“从数据库更新模型”无效。 我的数据库是DB2 - “Update Model From Database” does not work in .edmx Entities file. My Database is DB2 我可以从 edmx model 更新数据库表吗? - I can update database table from edmx model? 实体框架model.tt为空 - Entity framework model.tt is empty .edmx文件菜单中没有“数据库中的更新模型”? - “update model in database” not available in .edmx file menu? 实体框架 - Conext.tt 和 Model.tt 文件丢失 - Entity Framework - Conext.tt and Model.tt files missing 来自数据库Timeout的EDMX更新模型 - EDMX update model from database Timeout 如何从没有.tt和edmx文件的数据库优先方法获取表? - How to get tables from database first approach without .tt and edmx files? 如何在不影响所有其他模型类的情况下更新.edmx文件? - how to update .edmx file without effecting all the other model classes? 实体框架:从数据库更新模型时,丢失Model.edmx修改 - entity Framework : Model.edmx modifications are lost when update model from database 为什么当我在 Visual Studio 2017 中将存储过程添加到 edmx 时,我的复杂类型没有更新? - Why my complex types is not updated when i add a stored procedure into edmx in Visual Studio 2017?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM