Docs Menu
Docs Home
/ /
Atlas Device SDKs
/ /

Read Data - .NET SDK

On this page

  • Read from Realm
  • Query All Objects of a Given Type
  • Find a Specific Object by Primary Key

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.

Note

About the examples on this page

The examples on this page use the data model of a project management app that has two Realm object types: Project and Item. A Project has zero or more 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.

Example

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

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

You can find a specific item by its primary key using the Find method. The following example finds a single Project:

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

Back

Create

Next

Filter and Sort