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]
}
}
Post your comments / questions
Recent Article
- How to check PAN-Aadhaar is Linked or NOT?
- How to customize pagination for django admin?
- How to fix HAXM is not installed |in Android Studio
- How to fix CMOS Checksum Error in Computer or Laptop | SOLVED
- Reactivating windows after a Hardware change on PC or Laptop
- FIXED: Windows reported that the hardware of your device has changed. Error code :0xc004F211
- "redirect" is not defined pylance("reportUndefinedVariable)
- This action cannot be completed because the file is open in SQL Server(SQLEXPRESS) - FIXED
Related Article