I have the following code in a partial class and I'm using LINQ to SQL:
[Bind(Include = "OrderId,OrderTypeId,CustomerName,Price")]
[MetadataType(typeof(OrderMetadata))]
public partial class Order
{
}
public class OrderMetadata
{
[DisplayName("Customer Name")]
[Required]
public object CustomerName { get; set; }
}
I'm trying to write a test to see if 'CustomerName' is required amd am using this code I found here: http://bradwilson.typepad.com/blog/2009/04/index.html
var propertyInfo = typeof(Order).GetProperty("CustomerName");
var attribute = propertyInfo.GetCustomAttributes(typeof(RequiredAttribute), true).Cast().FirstOrDefault();
attribute is always null.
Can anyone help please?
Thanks
Davy