RavenDB:有没有办法从数据库中删除具体字段?
RavenDB: is there a way to remove the concrete field from DB?
我有这样一个 Raven 数据库文档结构:
{"Title":"abc",
"User":{"$type": "IOM.Server.Data", "Mail":...etc},
"Content": [
{
"Additional": {
"Title": "abc",
"$type": "IOM.Server.Data"
}
}]
}
在 Visual Studio (C#) 中出现错误 "Can't load assembly 'IOM.Server.Data'"。
我无法将此值读取为字符串,因为我无法拥有名为“$type”的变量。
现在我必须将用户和内容读取为对象类型,然后转换为 Json,然后从 Json 对象中获取信息。如果我可以从数据库中的任何地方(用户、内容附加)删除所有这些字段,因为我不需要它们,那会容易得多。有办法吗?这样解决问题对吗?
如果您在工作室中看到 $type,这意味着您可能已经实例化了 'User' 和 'Additional',其中 class 扩展了道具的基础 class 'User' 和 'Additional'。
顺便说一下,如果你想删除 $type 你可以使用 patch:
documentStore.DatabaseCommands.Patch("yourDocId/1",
new[]
{
new PatchRequest
{
Type = PatchCommandType.Modify,
Name = "User",
AllPositions = true,
Nested = new []
{
new PatchRequest
{
Type = PatchCommandType.Unset,
Name = "$type"
}
}
},
new PatchRequest
{
Type = PatchCommandType.Modify,
Name = "Content",
AllPositions = true,
Nested = new []
{
new PatchRequest
{
Type = PatchCommandType.Modify,
Name = "Additional",
AllPositions = true,
Nested = new []
{
new PatchRequest
{
Type = PatchCommandType.Unset,
Name = "$type"
}
}
}
}
}
});
希望这对您有所帮助
我有这样一个 Raven 数据库文档结构:
{"Title":"abc",
"User":{"$type": "IOM.Server.Data", "Mail":...etc},
"Content": [
{
"Additional": {
"Title": "abc",
"$type": "IOM.Server.Data"
}
}]
}
在 Visual Studio (C#) 中出现错误 "Can't load assembly 'IOM.Server.Data'"。
我无法将此值读取为字符串,因为我无法拥有名为“$type”的变量。
现在我必须将用户和内容读取为对象类型,然后转换为 Json,然后从 Json 对象中获取信息。如果我可以从数据库中的任何地方(用户、内容附加)删除所有这些字段,因为我不需要它们,那会容易得多。有办法吗?这样解决问题对吗?
如果您在工作室中看到 $type,这意味着您可能已经实例化了 'User' 和 'Additional',其中 class 扩展了道具的基础 class 'User' 和 'Additional'。 顺便说一下,如果你想删除 $type 你可以使用 patch:
documentStore.DatabaseCommands.Patch("yourDocId/1",
new[]
{
new PatchRequest
{
Type = PatchCommandType.Modify,
Name = "User",
AllPositions = true,
Nested = new []
{
new PatchRequest
{
Type = PatchCommandType.Unset,
Name = "$type"
}
}
},
new PatchRequest
{
Type = PatchCommandType.Modify,
Name = "Content",
AllPositions = true,
Nested = new []
{
new PatchRequest
{
Type = PatchCommandType.Modify,
Name = "Additional",
AllPositions = true,
Nested = new []
{
new PatchRequest
{
Type = PatchCommandType.Unset,
Name = "$type"
}
}
}
}
}
});
希望这对您有所帮助