I'm using various syntaxes of System.ComponentModel.DataAnnotations
within my Model. Wondering if there's any implications on DataAnnotations
placement using this short hand syntax and also the placement seen further below where DataAnnotations
are on the Attributes and not Accessor & Modifier methods.
My Model with what I believe is best practice placement for DataAnnotations
and this works as expected when I add OData support to my Database Context class not posted here
public class WebOrder
{
private Guid _id;
private float _total;
private string _name;
[Key]
public Guid Id { get; private set; }
[Required]
public float Total
{
get { return _total; }
set { _total = value; }
}
[Required]
public string Name { get => _name; set => _name = value; }
}
Would this placement of DataAnnotations
also be considered valid
public class WebOrder
{
[Key]
private Guid _id;
[Required]
private float _total;
[Required]
private string _name;
public Guid Id { get; private set; }
public float Total
{
get { return _total; }
set { _total = value; }
}
public string Name { get => _name; set => _name = value; }
}