Wednesday 5 June 2019

Adding Validation to Entity Models




The generated class ItemRequest will always be a partial class. This allows you to write a second partial class which is marked with the necessary data annotations. In your case the partial class ItemRequest would look like this:

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

//make sure the namespace is equal to the other partial class ItemRequest
namespace MvcApplication1.Models 
{
    [MetadataType(typeof(ItemRequestMetaData))]
    public partial class ItemRequest
    {
    }

    public class ItemRequestMetaData
    {
        [Required]
        public int RequestId {get;set;}

        //...
    }
}

1 comment:

  1. Download the Microsoft 70-347 Q&A PDF file easily to prepare Enabling Office 365 Services exam. It is particularly designed for Microsoft 70-347 exam and our Microsoft specialists have created this 70-347 Question Dumps observing the original 70-347 exam.

    ReplyDelete