Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
adospace authored Aug 28, 2024
1 parent 084c06f commit d6e775b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,28 @@ partial class Todo
Get the model context from the container

```csharp
var _modelContext = serviceProvider.GetService<IModelContext>();
var modelContext = serviceProvider.GetService<IModelContext>();
```

Create a Query for the model:

```csharp
var _query = _modelContext.Query<Todo>();
var query = modelContext.Query<Todo>();
```

A query is an object implementing INotifyCollectionChanged that notifies subscribers of any change to the list of models contained in the context.
You can freely create a query with custom linq, ordering results as you prefer:

```csharp
var _query = _modelContext.Query<Todo>(_=>_.Where(x => x.Done).OrderBy(x => x.Title));
var query = modelContext.Query<Todo>(_=>_.Where(x => x.Done).OrderBy(x => x.Title));
```
Notifications are raised only for those models that pass the filter and in the order specified.

Now just add an entity to your context and the query will receive the notification.

```csharp
_modelContext.Add(new Todo { Title = "Task 1" });
_modelContext.Save();
modelContext.Add(new Todo { Title = "Task 1" });
modelContext.Save();
```

Note that the `Save()` function is synchronous, it just signals to the context that you modified it. Entities are sent to the storage in a separate background thread.
Expand Down

0 comments on commit d6e775b

Please sign in to comment.