1
我有一個部分類下面的代碼,我使用LINQ to SQL:如果「客戶名稱」是必需的AMD現在用MVC DataAnnotations測試
[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; }
}
我試圖寫一個測試,看看此代碼我在此處找到:http://bradwilson.typepad.com/blog/2009/04/index.html
var propertyInfo = typeof(Order).GetProperty(「CustomerName」);
var attribute = propertyInfo.GetCustomAttributes(typeof(RequiredAttribute),true).Cast()。FirstOrDefault();
屬性始終爲空。
任何人都可以幫忙嗎?
感謝
戴維
我認爲你是正確的。看不到它看着它:) 非常感謝,戴維 – Davy 2009-09-10 13:28:11