Validation Asp.net Web Api:使用复杂嵌套对象的DataAnnotation验证

Validation Asp.net Web Api:使用复杂嵌套对象的DataAnnotation验证,validation,asp.net-web-api,data-annotations,Validation,Asp.net Web Api,Data Annotations,我使用的是asp.net web api 2.0,我有一个不是普通POCO对象的Dto类。它具有其他对象作为属性,如下所示 public class TransactionDto{ public string Description{get;set;} public string TransactionType{get;set;} //other transaction related properties public InvoiceDto Invoice{get;set;} } public

我使用的是asp.net web api 2.0,我有一个不是普通POCO对象的Dto类。它具有其他对象作为属性,如下所示

public class TransactionDto{
public string Description{get;set;}
public string TransactionType{get;set;}
//other transaction related properties
public InvoiceDto Invoice{get;set;}
}
public class InvoiceDto{
public DataTime InvoiceDate{get;set;}
public decimal VATAmount{get;set;}
public decimal InvoiceAmount{get;set;}
}
现在的场景是,如果
TransactionType
设置为
Invoice
,并且如果不是
Invoice
,我希望发票属性是
必需的
,那么我不关心与发票相关的属性。我怎样才能做到这一点?或者我必须使其成为普通POCO对象,并将
Invoice
的所有属性填充到
TransactionDto