我正在使用音乐商店示例数据,我有一个像这样的POCO:
public class Album
{
public Genre Genre { get; set; }
public Artist Artist { get; set; }
public string ID { get; set; } /***** NULL *****/
public string AlbumArtUrl { get; set; }
public double Price { get; set; }
public string Title { get; set; }
public int CountSold { get; set; }
}
但是,当我检索数据时,ID属性为null。如果我将属性更改为Id,则会填充它。这似乎表明该财产必须是某种情况。
以下是数据:
{
"AlbumArtUrl": "/Content/Images/placeholder.gif",
"Genre": {
"Id": "genres/1",
"Name": "Rock"
},
"Price": 8.99,
"Title": "Let There Be Rock",
"CountSold": 0,
"Artist": {
"Id": "artists/1",
"Name": "AC/DC"
}
}
有趣的是,对于流派&艺术家POCO改变POCO属性的情况并没有什么区别。我想知道它是否因为它明确地声明为JSON中的属性,而相册中的Id不是。
答案 0 :(得分:2)
默认情况下,我们在属性名称中查找名为“Id”的属性,是,大小写。
您可以通过更改Conventions.FindIdentityProperty
例如