Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
Click here >
Docs Menu
Docs Home
/ /
tipos de datos compatibles

Lists - .NET SDK

Una lista de reinos implementa Lista<T>y contiene cero o más instancias de un tipo Realm. Como un C# ListUna colección Realm es homogénea (todos los objetos de una colección son del mismo tipo).

Realm objects can contain lists of any supported data type. You create a collection by defining a getter-only property of type IList<T>, where T can be any data type (except other collections). A list of realm objects represents a to-many relationship between two Realm types, the containing class and the type in the list.

Lists are mutable: within a write transaction, you can add and remove elements on a list.

Borrar un objeto de la base de datos lo removerá de cualquier lista donde existiera. Por lo tanto, una lista de objetos nunca contendrá objetos borrados. Sin embargo, las listas de tipos primitivos pueden incluir valores nulos. Si no desea permitir valores nulos en una lista, entonces utilice tipos no nulos en la declaración de la lista (por ejemplo, utilice IList<double> en lugar de IList<double?>). Si utilizas la definición de tipo de esquema anterior (tus clases derivan de la clase base RealmObject), o no tienes habilitada la anulabilidad, utiliza el atributo [Required] si la lista contiene tipos de referencia anulables, como string o byte[].

Importante

No compatible con sincronizar

Local-only realms support collections of nullable (optional) values, but Sync does not.

For more information, refer to Required and Optional Properties.

You can use the INotifyCollectionChanged.CollectionChanged event on a list to watch for changes to the list, and the INotifyPropertyChanged.PropertyChanged event to watch for changes to specific properties in the list.

In the following code example, we have a class with an IList<string> property named StringList. We set up event handlers for both the CollectionChanged and PropertyChanged events:

var list = container.StringList.AsRealmCollection();
list.CollectionChanged += (sender, e) =>
{
Console.WriteLine($"List {sender} changed: {e.Action}");
};
list.PropertyChanged += (sender, e) =>
{
Console.WriteLine($"Property changed on {sender}: {e.PropertyName}");
};

Volver

Results Collections

En esta página