Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
CRUD

Read Data - .NET SDK

You can read back the data that you have stored in Realm by finding, filtering, and sorting objects.

You read from a realm with LINQ queries.

Nota

Acerca de los ejemplos de esta página

Los ejemplos de esta página utilizan el modelo de datos de una aplicación de gestión de proyectos que tiene dos tipos de objetos Realm: Project y Item. Un Project tiene cero o más Items:

public partial class Items : IRealmObject
{
[PrimaryKey]
[MapTo("_id")]
public ObjectId Id { get; set; } = ObjectId.GenerateNewId();
public string Name { get; set; }
public string Assignee { get; set; }
public bool IsComplete { get; set; }
public int Priority { get; set; }
public int ProgressMinutes { get; set; }
}
public partial class Project : IRealmObject
{
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; } = ObjectId.GenerateNewId();
public string Name { get; set; }
public IList<Items> Items { get; }
}

To read all objects of a certain type in a realm, call realm.All<T>, where T is the realm object type. You can then use the returned results collection to further filter and sort the results.

Ejemplo

In order to access all Projects and Items, use the following syntax:

var projects = realm.All<Project>();
var items = realm.All<Items>();

Puede encontrar un elemento específico por su clave principal utilizando el Método Find. El siguiente ejemplo busca un solo proyecto:

var myProject = realm.Find<Project>(projectId);

Volver

Crear

En esta página