RavenDb:如何建模c#类

时间:2014-04-12 15:17:47

标签: c# ravendb

我将这个Json数据作为ravenDb中的文档,但我不知道如何在我的MVC 5应用程序中建模我的c#-class / classes以使其工作。有人可以指出我正确的方向。感谢。

{
  "Name": "Finland",
  "Code": "4234",
  "Area": 25453,
  "Capital": "324234",
  "Province": "sfdfsf",
  "FlagId": "34",
  "ContinentCode": "6554",
  "ShipTo": {
      "Line1": "2817 Milton Dr.",
      "Line2": null,
      "City": "Albuquerque",
      "Region": "NM",
      "PostalCode": "87110",
      "Country": "USA"
   }
}

1 个答案:

答案 0 :(得分:0)

基本定义如下。我假设引号中的任何内容都是一个字符串,尽管它们包含整数。我认为JsonDeserializer可以使用它,但只是安全:

// TODO: Change class name to reflect document name
public class ShipToDetails
{
   public string Id { get; set; }
   public string Name { get; set; }
   public string Code { get; set;

   public int Area { get; set; }
   public string Capital { get; set; }
   public string Province { get; set; }
   public string FlagId { get; set; }
   public string ContinentCode { get; set; }

   public Address ShipTo { get; set; }
}

public class Address
{
   public string Line1 { get; set; }
   public string Line2 { get; set; }
   public string City { get; set; }
   public string Region { get; set; }
   public string PostalCode { get; set; }
   public string Country { get; set; }
}