I have the following:
[DataContract]
public class Video
{
[Key]
[DataMember(IsRequired = false)]
[Required]
public int VideoId { get; set; }
[DataMember(IsRequired = false)]
[Required]
public int UserId { get; set; }
[Required]
[DataMember(IsRequired=true)]
public string Title { get; set; }
}
The goal here is to tell WebAPI via the DataMember decorations that all I need on the wire is Title - the other two properties are not required for a valid request.
I'm then trying to tell Entity Framework / SQL that the other properties are required in the database. I will assign them in my service or webapi layers.
If I use the following to send only the title, I get
{"$id":"1","message":"The request is invalid.","modelState":{"$id":"2","video.VideoId":["A value is required."],"video.UserId":["The UserId property is required."]}}
What am I misunderstanding here? As far as I know, WebAPI shouldn't care that a videoId wasn't provided.