我有一個簡單的類,它是由實體框架5,類似於生成:的Web API 2 XML序列化是忽略MetadataType
public partial class Car
{
public string Model {get; set;}
// other properties follow...
}
我創建了一個伴侶類(以保持這些東西被覆蓋)和一個「夥伴級」當我在幫助/阿比運行該應用程序爲我的汽車的幫助頁面保存元數據::
[MetadataType(typeof(CarMetadata))]
public partial class Car { }
[DataContract("Automobile")]
public partial class CarMetadata
{
[DataMember]
public string Model {get; set;}
}
/GET-API的汽車模型給我這個錯誤:
An exception has occurred while using the formatter 'XmlMediaTypeFormatter'
to generate sample for media type 'application/xml'.
Exception message: One or more errors occurred.
該kicker是,如果我把EF生成的類DataAnnotations它工作正常。這就像它忽略了好友類...但是JSON格式化程序正在按預期翻譯它。
這給出正確的結果,在EF類,但它不能呆在那裏,或者它覆蓋:
[DataContract("Automobile")]
public partial class Car
{
[DataMember]
public string Model {get; set;}
// other properties follow...
}
任何援助將不勝感激。
這是最接近實際的問題。引用循環確實是問題。 –