C# 从RavenDb中的patchcommand返回实际修补的属性值
有一个“Billing”类,它描述了我在多线程应用程序中的财务帐户模型。如果我想把钱从一个账单转到另一个账单,我会发出一个命令,即递增一个属性,递减另一个属性。在没有冗余负载查询的情况下,修补后返回实际属性值的正确方法是什么 计费类 我的补丁方法C# 从RavenDb中的patchcommand返回实际修补的属性值,c#,ravendb,C#,Ravendb,有一个“Billing”类,它描述了我在多线程应用程序中的财务帐户模型。如果我想把钱从一个账单转到另一个账单,我会发出一个命令,即递增一个属性,递减另一个属性。在没有冗余负载查询的情况下,修补后返回实际属性值的正确方法是什么 计费类 我的补丁方法 您可以使用output()方法将值发送回用户。自RavenDb v3以来,ScriptedPatchRequest中提供的预定义JavaScript函数集具有方法output(message),该方法允许调试修补程序并在输出中打印传递的消息。请参阅文档
您可以使用
output()
方法将值发送回用户。自RavenDb v3以来,ScriptedPatchRequest
中提供的预定义JavaScript函数集具有方法output(message)
,该方法允许调试修补程序并在输出中打印传递的消息。请参阅文档以了解
见下例:
var balancePatch = dbSession.Advanced
.DocumentStore
.DatabaseCommands
.Patch(
billingDst /* document ID */,
new ScriptedPatchRequest
{
Script = @"this.Balance += money; output(this.Balance);",
Values = {{"money", money}}
});
// Reading the debug output
var balance = balancePatch["Debug"].Values().First().Value<decimal>();
var balancePatch=dbSession.Advanced
.DocumentStore
.数据库命令
.补丁(
billingDst/*文档ID*/,,
新的ScriptedPatchRequest
{
脚本=@“this.Balance+=money;输出(this.Balance);”,
价值={{“金钱”,金钱}
});
//读取调试输出
var balance=balancePatch[“Debug”].Values().First().Value();
public void TransferMoney(string billingSrc, string billingDst, decimal money)
{
_ctx.DatabaseCommands.Batch(new ICommandData[]
{
new ScriptedPatchCommandData
{
Key = billingSrc,
Patch = new ScriptedPatchRequest
{
Script = @"this.Balance -= money;",
Values = {{"money", money}}
}
},
new ScriptedPatchCommandData
{
Key = billingDst,
Patch = new ScriptedPatchRequest
{
Script = @"this.Balance += money;",
Values = {{"money", money}}
}
}
});
}
var balancePatch = dbSession.Advanced
.DocumentStore
.DatabaseCommands
.Patch(
billingDst /* document ID */,
new ScriptedPatchRequest
{
Script = @"this.Balance += money; output(this.Balance);",
Values = {{"money", money}}
});
// Reading the debug output
var balance = balancePatch["Debug"].Values().First().Value<decimal>();