1

i am working on an asp.net mvc-4 web application . and i am using Entity Framework 5. where i mapped my database tables using EF.

now i use to have the following model class inside my .tt folder:-

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. 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. now the model inside the .edmx file got the new columns/relation correctly as follow:-

enter image description here

but my related .tt class is still referencing the old columns. i was expecting my .tt model class to be as follow:-

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 ? and is there any problem if i manually modify the related .tt classes to get the new columns/ relation ?

John John
  • 1
  • 72
  • 238
  • 501

1 Answers1

7
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.
BSG
  • 2,084
  • 14
  • 19
  • thanks for the reply... but will this update the whole .tt classes ? or only the ones which got updated ? as i do not want to regenerated the whole .tt model classes.. since in this case i will lose some settings which i have applied to the .edmx such as the concurrency mode for some entities ... i remember previously when i chose to update the .edmx from database the related model classes inside the .tt folder will also be updated .. but not sure i did not get this inside my current project... – John John May 04 '16 at 15:20
  • Did this, even though the edmx file was changed, there were still no changes to the intended class in the .tt file. Using VS 2019 version 16.9.2 – Bojan Mar 25 '21 at 09:40