我试图在MVC项目中学习RavenDB ...让我们说我们在RavenDB集合中存储了很多文档,看起来像这样:
"ShipVia": "shippers/2",
"Freight": 18.66,
"Lines": [
{
"Product": "products/25",
"ProductName": "NuNuCa Nuß-Nougat-Creme",
},
通过这样做,我设法显示了一个单一的属性(例如" Freight"): 类:
public class Orders
{
public string Freight { get; set; }
}
然后创建一个带有List-template的硬类型视图...这样就可以获得数据库中的所有Freights属性...
我想抓住" Lines" -property并能够看到产品和产品名称......试过这个:
namespace World.DAL
{
public class Orders
{
public string Company { get; set; }
public string Employee { get; set; }
public List<Lines> Lines { get; set; }
}
public class Lines
{
public string Product { get; set; }
public string ProductName { get; set; }
}
}
那没关系。我想回到了一个空位清单。有人能指出我正确的方向吗?
编辑:
{
"Company": "companies/65",
"Employee": "employees/5",
"OrderedAt": "1997-12-02T00:00:00.0000000",
"RequireAt": "1997-12-30T00:00:00.0000000",
"ShippedAt": "1997-12-08T00:00:00.0000000",
"ShipTo": {
"Line1": "2817 Milton Dr.",
"Line2": null,
"City": "Albuquerque",
"Region": "NM",
"PostalCode": "87110",
"Country": "USA"
},
"ShipVia": "shippers/2",
"Freight": 18.66,
"Lines": [
{
"Product": "products/25",
"ProductName": "NuNuCa Nuß-Nougat-Creme",
"PricePerUnit": 14.0,
"Quantity": 35,
"Discount": 0.25
},
{
"Product": "products/75",
"ProductName": "Rhönbräu Klosterbier",
"PricePerUnit": 7.75,
"Quantity": 18,
"Discount": 0.0
}
]
}
答案 0 :(得分:1)
您的类需要完全匹配json格式,这意味着您的类需要如下所示:
public class Orders
{
public string ShipVia { get; set; }
public string Freight { get; set; }
public List<Lines> Lines { get; set; }
}
当然你的行类仍需要声明
public class Lines
{
public string Product { get; set; }
public string ProductName { get; set; }
}