简体   繁体   English

如何在更新 lite DB 记录时防止从字段中删除空间

[英]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.

相关问题 如何防止“抽绳”被去除? - How to prevent “drawstring” from being removed? 如何在初始化控件时阻止PropertyChanged触发 - How to prevent PropertyChanged from firing while controls are being initialized 如何检测正在从文件夹中删除的文件 - How to detect a file being removed from folder 防止在枚举时修改集合 - Prevent collection from being modified while enumerating 如何防止class在库外被继承,同时被公共类继承? - How to prevent a class from being inherited outside the library, while being inherited by public classes? JMS:更新消息版本/防止某些消息进入队列 - JMS: updating message version / prevent certain message from being queued WPF ComboBox (with IsEditable) - 防止从选项列表中删除所选项目 - WPF ComboBox (with IsEditable) - Prevent selected item from being deleted when removed from the list of choices 如何防止在createuserwizard控件中更改用户名字段。 asp.net - How to prevent username field from being changed in the createuserwizard control. asp.net 安装/部署项目:防止在卸载时删除已修改的文件 - Setup/Deployment project: Prevent modified files from being removed when uninstalling 如何在内存中运行时防止我的程序集被保存? - How Can I Prevent My Assembly From Being Saved While Running in Memory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM