Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 为什么当我选择从数据库更新.edmx文件时Model.tt类不会得到更新_Entity Framework_Entity Framework 5_Edmx_Edmx Designer - Fatal编程技术网

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

Entity framework 为什么当我选择从数据库更新.edmx文件时Model.tt类不会得到更新,entity-framework,entity-framework-5,edmx,edmx-designer,Entity Framework,Entity Framework 5,Edmx,Edmx Designer,我正在开发一个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 {

我正在开发一个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; }

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

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; }
    }

但是我的相关.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类以获得新的列/关系,是否有任何问题?

感谢您的回复。。。但是这会更新整个.tt类吗?还是只更新了那些?因为我不想重新生成整个.tt模型类。。因为在这种情况下,我将丢失一些应用于.edmx的设置,例如某些实体的并发模式。。。我记得以前我选择从数据库更新.edmx时,.tt文件夹中的相关模型类也将更新。。但是我不确定我在当前的项目中没有得到这个…这样做了,即使edmx文件被更改,在.tt文件中仍然没有对预期的类进行更改。使用VS 2019版本16.9.2作为回复。。。但是这会更新整个.tt类吗?还是只更新了那些?因为我不想重新生成整个.tt模型类。。因为在这种情况下,我将丢失一些应用于.edmx的设置,例如某些实体的并发模式。。。我记得以前我选择从数据库更新.edmx时,.tt文件夹中的相关模型类也将更新。。但是我不确定我在当前的项目中没有得到这个…这样做了,即使edmx文件被更改,在.tt文件中仍然没有对预期的类进行更改。使用VS 2019版本16.9.2
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.