[英]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.