[英]How to prevent space being removed from the field while updating the lite DB record
I am using lite DB for my WPF application.我正在为我的 WPF 应用程序使用 lite DB。 I am using the following function to update the record in lite DB.
我正在使用以下 function 来更新 lite DB 中的记录。
public void Update(T data)
{
(DBInstance as LiteDBInstance).LiteDatabase.GetCollection<T>(TableName).Update(data);
}
The following is the data I am trying to update以下是我要更新的数据
{
"_id": "5005e877-25fc-483d-a652-f9b223a65add",
"ProjectID": "3d11b869-1c9e-486b-9451-825e03461b2c",
"Result": "PASS",
"Errors": [
],
"HostLogCount": 0,
"CardLogCount": 0,
"TrxLogs": [
{
"Result": "PASS",
"HostLogs": [
{
"_id": null,
"Transactions": [
{
"MTI": "0100",
"UniqueNumber": "0710114729010019",
"Elements": [
{
"_id": "000",
"Value": "0100",
},
{
"_id": "002",
"Value": "4176662220010018 ",
},
{
"_id": "003",
"Value": " ",
}
]
}
]
}
]
}
]
}
The problem I am facing in this is, after the update operation, the record in the DB looks like我面临的问题是,在更新操作之后,数据库中的记录看起来像
{
"_id": "002",
"Value": "4176662220010018",
},
{
"_id": "003",
"Value": "",
}
The difference is space in the ID Value is removed.不同之处在于 ID值中的空格被删除。 How to prevent this?
如何防止这种情况?
it works fine after modifying as per the comment made by @ Roar S.根据@ Roar S 的评论修改后效果很好。
However, I am reposting the same here但是,我在这里重新发布相同的内容
A quick search for this topic revealed that this the default behavior, hence you'll have to modify your config as described here:对该主题的快速搜索显示这是默认行为,因此您必须按照此处所述修改配置:
Now BsonMapper has a global instance that can be changed before using LiteDatabase.
现在 BsonMapper 有一个全局实例,可以在使用 LiteDatabase 之前进行更改。 BsonMapper.Global.TrimWhitespace = false;
BsonMapper.Global.TrimWhitespace = false;
https://github.com/mbdavid/LiteDB/issues/181 https://github.com/mbdavid/LiteDB/issues/181
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.