Raven DB SQL Replication如何处理将数组保存到SQL?

时间:2013-03-19 11:34:41

标签: sql ravendb database-replication

我目前正在设置SQL Replication以将我们的Raven DB文档复制到SQL中以进行报告。到目前为止,一切都很好。但是,我现在正在尝试保存包含一周中几天的数组的文档。

这是文档在Raven中的样子:

{
  "ClientId": "clients/385",
  "Description": "Test",
  "IsOneOff": false,
  "RecursEveryWeeks": 1,
  "StartDate": "2013-03-19T00:00:00.0000000",
  "TaskStartTime": "12:00:00",
  "TaskDuration": 120,
  "TaskEndTime": "14:00:00",
  "AdditionalResources": false,
  "AdditionalVisitType": "TestType",
  "BillableTo": "Private",
  "RecurrenceEndDate": "2013-04-30T00:00:00.0000000",
  "DaysOfWeek": [
    "Monday",
    "Tuesday",
    "Wednesday",
    "Friday",
    "Saturday"
  ]
}

在SQL Replication中,我完成了以下操作:

sqlReplicate("AdditionalVisit", "AdditionalVisitId", {
       ClientId: this.ClientId,
       Description: this.Description,
       IsOneOff: this.IsOneOff,
       RecursEveryWeeks: this.RecursEveryWeeks,
       StartDate: this.StartDate,
       TaskStartTime: this.TaskStartTime,
       TaskDuration: this.TaskDuration,
       TaskEndTime: this.TaskEndTime,
       AdditionalResources: this.AdditionalResources,
       AdditionalVisitType: this.AdditionalVisitType,
       BillableTo: this.BillableTo,
       RecurrenceEndDate: this.RecurrenceEndDate,
       DaysOfWeek: this.DaysOfWeek
});

当我将DaysOfWeek从SQL Replication中删除但导致服务器在我离开时崩溃时,所有这一切都正常。

如何在SQL Replication中完成此操作,以便将数组中的所有内容保存到SQL中的DaysOfWeek列?

1 个答案:

答案 0 :(得分:1)

我没有对此进行过测试,但它符合您的要求......只需将其添加到当前脚本的末尾即可。

for (var i=0; i<this.DaysOfWeek.length; i++) {
    var day = this.DaysOfWeek[i];
    sqlReplicate('AdditionalVisit_DaysOfWeek', 'AdditionalVisitId', {
        AdditionalVisitId: documentId,
        DayOfWeek: day,
    });
}

顺便说一下,目前在RavenDb 2.1的SqlReplication中存在一个错误,其中删除不会被推送到SqlReplication,它应该在2.5分支中被修复但是仍然有一些其他问题需要处理它变得可用了。