Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
i am working on an MVC application and have used EF. [Database first approach].
I created Scaffold Template from EF. I have 2 tables tblEmployee and tblDepartment. Changed their name in edmx designer to Employee and Department.

Now when i go to index view which shows me all the employees there are two columns with name "Name" , one for employee and one for department. So now i want to change the Column name "Name" for department to "Department Name".

As i am using DB first approach can't do the changes in DataModel.Designer.cs
SO i created a partial class Department [ name is same as in Designer.cs]
decorated it with MetaDataType attribute and passed a class with name property to the type parameter.

All good till now. But now when i run the project i don't see the changes in the Index view. don't know what to do now.I am New to MVC. any sort of help is much appriciated !!!

What I have tried:

This is the new partial class that i created
[MetadataType( typeof(DepartmentMetaData))]
    public partial class Department
    {
    }

    public class DepartmentMetaData
    {
        [Display(Name = "Department Name")]
        public string Name { get; set; }
    }



this is the property in DataModel.Designer.cs
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
      [DataMemberAttribute()]
      public global::System.String Name
      {
          get
          {
              return _Name;
          }
          set
          {
              OnNameChanging(value);
              ReportPropertyChanging("Name");
              _Name = StructuralObject.SetValidValue(value, true);
              ReportPropertyChanged("Name");
              OnNameChanged();
          }
      }


so the name of the property matches and there is a partial class . It should now change the name while showing records but it isn't. Please tell me if i missed something.
Posted
Updated 28-Sep-18 0:13am
v2

Turns Out My EDMX file was outside my Model Folder in which i had created my Partial class. Either both needs to be outside or both needs to be inside the folder. As soon as i changed the location of my class it started working. :)
 
Share this answer
 
Your model class and meta class that you have created both should have same namespace like :

namespace AppName.Models
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900