I have following Entity:
public class Document
{
public int Id { get; set; }
[Required]
public string Number { get; set; }
public int Version { get; set; }
//other properties with [Required]
}
I wrote a method to update only Version of one Document:
public void SetDocumentVersion(int docId, int version)
{
var doc = new Document() { Id = docId, Version= version };
using (var db = new MyEfContextName())
{
db.Documents.Attach(doc);
db.Entry(doc).Property(x => x.Version).IsModified = true;
db.SaveChanges(); //<--- get error
}
}
But when I run the method I get following Error:
The Number field is required.
Is there any way to bypass this validation?
[Required]attribute. Error message is self explanatory...