Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2539

_t Discriminator is lost when using ReplaceOneAsync

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.7.3
    • Component/s: Serialization
    • Labels:
      None
    • Environment:
      Visual Studio 2017, C#

      I am using the following generic code to replace a document with an updated version

       public async Task UpdateAsync<T>(T model, string collectionName) {
       var filter = Builders<T>.Filter.Eq("_id", model.Id);
       await database.GetCollection<T>(collectionName).ReplaceOneAsync(filter, model);
      }
      

      The documents are stored with a _t discriminator like that:

      { "_id" : "5c7fb949d0c890000179bb46", "_t" : "Type",  ....
      

      After using ReplaceOneAsync the _t discriminator is removed from the file in the database.
      I guess a workaround would be to manually cast model as the specific type and update all fields, which would result in _t not getting modified. (The question is if that is less performing.)

            Assignee:
            Unassigned Unassigned
            Reporter:
            mattll Martin Schneider
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: