Entity Framework's auto generated class's code gets re generated every time model is updated

asp.net-mvc c# entity-framework entity-framework-6 sql-server


To create entity classes, I'm using ADO.Net Entity Data Model, which links to a SQL Server database.

For the produced classes with this property, I'm making partial classes:


to putDataAnnotations within the fields. I thus delete all fields from the produced class (.g.cs ) and transfer them to the other partial class, adding this class to the data annotations.

The issue is that the created classes code is always generated again everytime I update the model from the database, regardless of whether I delete any existing tables from the entity data model beforehand or simply refresh the model. And once again, I must remove the field characteristics manually fromg.cs due to the fact that they are already present in other partial classes (in the class indicated by theMetadataType attribute).

Is it conceivable that the produced code is not updated when I alter the model and that, if necessary, I may manually regenerate the code for a specific table or class?

    public partial class Employee
        public string badge_no { get; set; }
        public string first_name { get; set; }
        public string last_name { get; set; }

        public string FullName { get { return first_name + " " + last_name; } }

        [Display(Name = "Badge-Name")]
        public string NameAndBadge { get { return badge_no + " " + FullName; } }

And now for theg.cs file (generated file)

    public partial class Employee
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public Employee()
            this.EmpWrkDesignations = new HashSet<EmpWrkDesignation>();

        public int id { get; set; }
        //public string badge_no { get; set; }
        //public string first_name { get; set; }
        //public string last_name { get; set; }
        public System.DateTime row_added_date { get; set; }
        public Nullable<System.DateTime> row_changed_date { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<EmpWrkDesignation> EmpWrkDesignations { get; set; }
9/17/2017 7:57:50 AM

Popular Answer

9/17/2017 8:35:38 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow