views:

121

answers:

1

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

A: 

I think you need to get type OrderMetadata not Order

var propertyInfo = typeof(OrderMetadata).GetProperty("CustomerName");

Kindness,

Dan

Daniel Elliott
I think you're correct. Couldn't see it ofr looking at it :)Thank a lot, Davy
Davy