Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahuldass/066f8e54c5469e570392 to your computer and use it in GitHub Desktop.
Save rahuldass/066f8e54c5469e570392 to your computer and use it in GitHub Desktop.
Customizing Autogenerated classes in MVC 4 #mvc4

###Customizing Autogenerated classes in MVC 4

In order to customize classes autogenerated by .edmx add a new class file in Models folder.

Eg: Department.cs or DepartmentCustom.cs

Copy and paste the following code in "Department.cs" file

namespace MVCDemo.Models
{
	[MetadataType(typeof(DepartmentMetaData))]
	public partial class Department
	{
	
	}
	
	public class DepartmentMetaData
	{
	    [Display(Name="Department Name")]
	    public string Name { get; set; }
	}
}

for validation

namespace MVCDemo.Models
{
    [MetadataType(typeof(EmployeeMetaData))]
    public partial class Employee
    {
    
    }

    public class EmployeeMetaData
    {
        [Required]
        public string Name { get; set; }

        [Required]
        public string Gender { get; set; }

        [Required]
        public string City { get; set; }

        [Required]
        [Display(Name="Department")]
        public int DepartmentId { get; set; }
    }
}

Use "System.ComponentModel.DataAnnotations" namespace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment