简体   繁体   中英

How to prevent space being removed from the field while updating the lite DB record

I am using lite DB for my WPF application. I am using the following function to update the record in 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. How to prevent this?

it works fine after modifying as per the comment made by @ 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.Global.TrimWhitespace = false;

https://github.com/mbdavid/LiteDB/issues/181

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM