Los SDK de dispositivos Atlas están obsoletos. Consulte deprecation page for details.
Updates are the same as creating a new document. When updating documents, all writes must happen in a transaction.
Modify an Object
El siguiente ejemplo muestra cómo modificar un objeto existente. En este ejemplo, actualizamos el Name y Age propiedades de un objeto Dog:
var dog = realm.All<Dog>().First(); realm.WriteAsync(() => { dog.Name = "Wolfie"; dog.Age += 1; });
Upserts
Una inserción te permite crear o modificar un documento sin saber si el documento ya existe. Para obtener más información, consulta Actualizar un objeto Realm.
Update a Collection
The following code demonstrates how to update a collection.
realm.Write(() => { // Create someone to take care of some dogs. var ali = new Person { Id = id, Name = "Ali" }; realm.Add(ali); // Find dogs younger than 2. var puppies = realm.All<Dog>().Where(dog => dog.Age < 2); // Loop through one by one to update. foreach (var puppy in puppies) { // Add Ali to the list of Owners for each puppy puppy.Owners.Add(ali); } });
Nota
Because realm uses implicit inverse relationships between the Dog's Owners property and the Person's Dogs property, Realm automatically updates Ali's list of dogs at the same time we update each dog's Owners list.