MVC 데이터 오노 테스트
-
05-07-2019 - |
문제
부분 클래스에 다음 코드가 있으며 LINQ에서 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; }
}
'CustomerName'이 필요한지 확인하기 위해 테스트를 작성하려고합니다. 여기에서 찾은이 코드를 사용하고 있습니다. http://bradwilson.typepad.com/blog/2009/04/index.html
var propertyinfo = typeof (order) .getProperty ( "CustomerName");
var attribute = propertyInfo.getCustomAttributes (typeof (requirettribute), true) .cast (). firstordeFault ();
속성은 항상 널입니다.
누구든지 제발 도와 줄 수 있습니까?
감사
데이비
해결책
나는 당신이 Order OrderTMetadata 유형을 가져와야한다고 생각합니다.
var propertyInfo = typeof(OrderMetadata).GetProperty("CustomerName");
친절,
단
제휴하지 않습니다 StackOverflow