我在尝试从默认的RavenDB数据库加载Album文档时收到FormatException:
using (var session = _documentStore.OpenSession())
{
var album = session.Load<Album>(500);
//....
}
数据库中的Album JSON文档如下所示:
{
"AlbumArtUrl": "/Content/Images/placeholder.gif",
"Genre": {
"Id": "genres/10",
"Name": "Classical"
},
"Price": 8.99,
"Title": "The Best of Beethoven",
"CountSold": 0,
"Artist": {
"Id": "artists/203",
"Name": "Nicolaus Esterhazy Sinfonia"
}
}
我的内存实体Album类看起来像这样:
public class Album
{
public long Id { get; set; }
public string AlbumArtUrl { get; set; }
public DenomralizedGenre Genre { get; set; }
public decimal Price { get; set; }
public string Title { get; set; }
public int CountSold { get; set; }
public DenomralizedArtist Artist { get; set; }
}
public class DenomralizedGenre
{
public int Id { get; set; }
public string Name { get; set; }
}
public class DenomralizedArtist
{
public int Id { get; set; }
public string Name { get; set; }
}
我在这里做错了什么?
答案 0 :(得分:1)
制作所有Id字符串。你把它们作为int和long。在RavenDB中,Id是字符串。
作为字符串的Id将是RavenDB中的Album / 24。类名称或类型加上HiLo值(由客户端工具创建)构成Id。