C# 在c中使用tcp或存储过程大容量插入documentdb#

C# 在c中使用tcp或存储过程大容量插入documentdb#,c#,asp.net-web-api2,azure-cosmosdb,document-database,C#,Asp.net Web Api2,Azure Cosmosdb,Document Database,这是我的c代码 我需要解释的最终结果 最初我调用一个外部API来获取酒店的详细信息和他们的库存,下面是一个示例请求和调用外部API后得到的响应 请求为json: { "Version": "1.2", "EchoToken": "879791878", "RoomRatePlans": { "HotelCriteria": { "HotelCode": "101920" } } } 以及我得到的回应 { "HotelCriteria": { "H

这是我的c代码

我需要解释的最终结果

最初我调用一个外部API来获取酒店的详细信息和他们的库存,下面是一个示例请求和调用外部API后得到的响应

请求为json:

{
   "Version": "1.2",
   "EchoToken": "879791878",
   "RoomRatePlans": {
  "HotelCriteria": {
     "HotelCode": "101920"
  }
  }
}
以及我得到的回应

{
"HotelCriteria": {
    "HotelCode": "NONIDS",
    "HotelName": "TestThe Zuri Whitefield Bengaluru"
},
"RoomTypes": {
    "RoomTypeList": [
        {
            "InvTypeCode": "ZCR",
            "Name": "Zuri Club Room",
            "BaseOccupancy": 2,
            "MaxOccupancy": 3,
            "Quantity": 66,
            "IsRoomActive": 1,
            "RoomDescription": ""
        },
        {
            "InvTypeCode": "ZRR",
            "Name": "Zuri Room",
            "BaseOccupancy": 2,
            "MaxOccupancy": 3,
            "Quantity": 90,
            "IsRoomActive": 1,
            "RoomDescription": ""
        },
        {
            "InvTypeCode": "ZSR",
            "Name": "Zuri Suite Room",
            "BaseOccupancy": 2,
            "MaxOccupancy": 3,
            "Quantity": 4,
            "IsRoomActive": 1,
            "RoomDescription": ""
        }
    ]
},
"RatePlans": {
    "RatePlanList": [
        {
            "RatePlanCode": "B2C00001",
            "RatePlanCategory": "B2C",
            "RatePlanStatusType": 1,
            "RatePlanName": "Channel Rates",
            "Description": "Channel Rates",
            "InvTypeCode": "ZCR",
            "MealPlanCode": "CP",
            "MealPlanDesc": "Continental Plan",
            "Start": "2016-06-27",
            "End": "2017-03-31",
            "CurrencyCode": "INR"
        },
        {
            "RatePlanCode": "B2C00001",
            "RatePlanCategory": "B2C",
            "RatePlanStatusType": 1,
            "RatePlanName": "Channel Rates",
            "Description": "Channel Rates",
            "InvTypeCode": "ZRR",
            "MealPlanCode": "CP",
            "MealPlanDesc": "Continental Plan",
            "Start": "2016-06-27",
            "End": "2017-03-31",
            "CurrencyCode": "INR"
        },
        {
            "RatePlanCode": "B2C00001",
            "RatePlanCategory": "B2C",
            "RatePlanStatusType": 1,
            "RatePlanName": "Channel Rates",
            "Description": "Channel Rates",
            "InvTypeCode": "ZSR",
            "MealPlanCode": "CP",
            "MealPlanDesc": "Continental Plan",
            "Start": "2016-06-27",
            "End": "2017-03-31",
            "CurrencyCode": "INR"
        }
    ]
},
"Inclusions": {
    "InclusionList": [
        {
            "MealPlanCode": "CP",
            "MealPlanDesc": "Continental Plan"
        }
    ]
}
}
我得到的响应的模型类

        public class HotelCriteria
    {
        public string HotelCode { get; set; }
        public string HotelName { get; set; }
    }

    public class RoomTypeList
    {
        public string InvTypeCode { get; set; }
        public string Name { get; set; }
        public int BaseOccupancy { get; set; }
        public int MaxOccupancy { get; set; }
        public int Quantity { get; set; }
        public int IsRoomActive { get; set; }
        public string RoomDescription { get; set; }
    }

    public class RoomTypes
    {
        public List<RoomTypeList> RoomTypeList { get; set; }
    }

    public class RatePlanList
    {
        public string RatePlanCode { get; set; }
        public string RatePlanCategory { get; set; }
        public int RatePlanStatusType { get; set; }
        public string RatePlanName { get; set; }
        public string Description { get; set; }
        public string InvTypeCode { get; set; }
        public string MealPlanCode { get; set; }
        public string MealPlanDesc { get; set; }
        public string Start { get; set; }
        public string End { get; set; }
        public string CurrencyCode { get; set; }
    }

    public class RatePlans
    {
        public List<RatePlanList> RatePlanList { get; set; }
    }

    public class InclusionList
    {
        public string MealPlanCode { get; set; }
        public string MealPlanDesc { get; set; }
    }

    public class Inclusions
    {
        public List<InclusionList> InclusionList { get; set; }
    }

    public class RootObject
    {
        public HotelCriteria HotelCriteria { get; set; }
        public RoomTypes RoomTypes { get; set; }
        public RatePlans RatePlans { get; set; }
        public Inclusions Inclusions { get; set; }

    }
公共级酒店标准
{
公共字符串HotelCode{get;set;}
公共字符串HotelName{get;set;}
}
公共类房间类型列表
{
公共字符串InvTypeCode{get;set;}
公共字符串名称{get;set;}
公共整数{get;set;}
公共int maxOccupation{get;set;}
公共整数数量{get;set;}
公共int是只读的{get;set;}
公共字符串RoomDescription{get;set;}
}
公共教室类型
{
公共列表RoomTypeList{get;set;}
}
公营课差饷租值表
{
公共字符串RatePlanCode{get;set;}
公共字符串RatePlanCategory{get;set;}
公共int-RatePlanStatusType{get;set;}
公共字符串RatePlanName{get;set;}
公共字符串说明{get;set;}
公共字符串InvTypeCode{get;set;}
公共字符串MealPlanCode{get;set;}
公共字符串MealPlanDesc{get;set;}
公共字符串开始{get;set;}
公共字符串结束{get;set;}
公共字符串CurrencyCode{get;set;}
}
公营课差饷计划
{
公共列表RatePlanList{get;set;}
}
公共类包含列表
{
公共字符串MealPlanCode{get;set;}
公共字符串MealPlanDesc{get;set;}
}
公共类包含
{
公共列表包含列表{get;set;}
}
公共类根对象
{
公共HotelCriteria HotelCriteria{get;set;}
公共RoomTypes RoomTypes{get;set;}
公共费率计划费率计划{get;set;}
公共包含{get;set;}
}
因此,我有一个1500家酒店的列表,我将调用rest API来获取每个酒店及其库存详细信息。反过来,我希望每个响应都作为单个文档保存在documentdb中,因此我的集合中总共应该有1500个文档。因此,如果我使用foreach并使用CreateDocumentSync方法,这是一个正确的选择还是我的选择在列表中包含我的1500个文档详细信息后,可以批量插入记录。需要您的建议和帮助


提前谢谢

您的代码不是传统的ado.net,但在我看来,我强烈建议您使用bulkinsert,因为它是为大规模插入文件/数据/文档而设计的。您只需在一次插入之前循环所有1500个文档。

那么使用for loop并将它们添加到列表中,然后进行批量插入?顺便说一句,这不是ado.net,我正在使用azure documentdb和c#web api 2。是的,没错!我没有使用WebAPI2,只有asmx,但是传统的ado.net仍然可以在mvc/WebAPI中使用,但是只需从您喜欢使用的地方开始。同样的逻辑/方法
{
"HotelCriteria": {
    "HotelCode": "NONIDS",
    "HotelName": "TestThe Zuri Whitefield Bengaluru"
},
"RoomTypes": {
    "RoomTypeList": [
        {
            "InvTypeCode": "ZCR",
            "Name": "Zuri Club Room",
            "BaseOccupancy": 2,
            "MaxOccupancy": 3,
            "Quantity": 66,
            "IsRoomActive": 1,
            "RoomDescription": ""
        },
        {
            "InvTypeCode": "ZRR",
            "Name": "Zuri Room",
            "BaseOccupancy": 2,
            "MaxOccupancy": 3,
            "Quantity": 90,
            "IsRoomActive": 1,
            "RoomDescription": ""
        },
        {
            "InvTypeCode": "ZSR",
            "Name": "Zuri Suite Room",
            "BaseOccupancy": 2,
            "MaxOccupancy": 3,
            "Quantity": 4,
            "IsRoomActive": 1,
            "RoomDescription": ""
        }
    ]
},
"RatePlans": {
    "RatePlanList": [
        {
            "RatePlanCode": "B2C00001",
            "RatePlanCategory": "B2C",
            "RatePlanStatusType": 1,
            "RatePlanName": "Channel Rates",
            "Description": "Channel Rates",
            "InvTypeCode": "ZCR",
            "MealPlanCode": "CP",
            "MealPlanDesc": "Continental Plan",
            "Start": "2016-06-27",
            "End": "2017-03-31",
            "CurrencyCode": "INR"
        },
        {
            "RatePlanCode": "B2C00001",
            "RatePlanCategory": "B2C",
            "RatePlanStatusType": 1,
            "RatePlanName": "Channel Rates",
            "Description": "Channel Rates",
            "InvTypeCode": "ZRR",
            "MealPlanCode": "CP",
            "MealPlanDesc": "Continental Plan",
            "Start": "2016-06-27",
            "End": "2017-03-31",
            "CurrencyCode": "INR"
        },
        {
            "RatePlanCode": "B2C00001",
            "RatePlanCategory": "B2C",
            "RatePlanStatusType": 1,
            "RatePlanName": "Channel Rates",
            "Description": "Channel Rates",
            "InvTypeCode": "ZSR",
            "MealPlanCode": "CP",
            "MealPlanDesc": "Continental Plan",
            "Start": "2016-06-27",
            "End": "2017-03-31",
            "CurrencyCode": "INR"
        }
    ]
},
"Inclusions": {
    "InclusionList": [
        {
            "MealPlanCode": "CP",
            "MealPlanDesc": "Continental Plan"
        }
    ]
}
}
        public class HotelCriteria
    {
        public string HotelCode { get; set; }
        public string HotelName { get; set; }
    }

    public class RoomTypeList
    {
        public string InvTypeCode { get; set; }
        public string Name { get; set; }
        public int BaseOccupancy { get; set; }
        public int MaxOccupancy { get; set; }
        public int Quantity { get; set; }
        public int IsRoomActive { get; set; }
        public string RoomDescription { get; set; }
    }

    public class RoomTypes
    {
        public List<RoomTypeList> RoomTypeList { get; set; }
    }

    public class RatePlanList
    {
        public string RatePlanCode { get; set; }
        public string RatePlanCategory { get; set; }
        public int RatePlanStatusType { get; set; }
        public string RatePlanName { get; set; }
        public string Description { get; set; }
        public string InvTypeCode { get; set; }
        public string MealPlanCode { get; set; }
        public string MealPlanDesc { get; set; }
        public string Start { get; set; }
        public string End { get; set; }
        public string CurrencyCode { get; set; }
    }

    public class RatePlans
    {
        public List<RatePlanList> RatePlanList { get; set; }
    }

    public class InclusionList
    {
        public string MealPlanCode { get; set; }
        public string MealPlanDesc { get; set; }
    }

    public class Inclusions
    {
        public List<InclusionList> InclusionList { get; set; }
    }

    public class RootObject
    {
        public HotelCriteria HotelCriteria { get; set; }
        public RoomTypes RoomTypes { get; set; }
        public RatePlans RatePlans { get; set; }
        public Inclusions Inclusions { get; set; }

    }