c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
ADO.NET

How to overwite entity framework data model in asp.net?

| | CSharp , MVC

You can overwrite entity framework data model class by defining separate class using partial keyword.

Create an ado.net entity data model using table Post and generate entity for that. Do not write validation in this autogenerated class because if you’re editing table and updating entity will clear validation and user defined property.

  public partial class Post

    {       
        public int PostId { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }

    }

Create your own user defined validation for the table post in separate class called myclass.cs because if you edited the table and generating

[Table("Post")]
    [MetadataType(typeof(PostMetadata))]
    public partial class Post
    {
        internal sealed class PostMetadata
        {
            [AllowHtml]
            public string Title { get; set; }
     [AllowHtml]
            [StringLength(500, ErrorMessage = "Description can acceptmaximum 500 characters.")]
            public string Description { get; set; }
            [AllowHtml]
            [Required]

       }
   }