![](/img/trans.png)
[英]“Update Model From Database” does not work in .edmx Entities file. My Database is DB2
[英]why the Model.tt classes will not get updated when i chose to update my .edmx file from database
我正在asp.net mvc-4 Web应用程序上工作。 我正在使用Entity Framework5。在这里,我使用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文件,然后选择从数据库更新模型,在该数据库中选择实际表并单击“更新”。 现在,.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类以获取新的列/关系,是否有任何问题?
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.