Skip to content

Commit 37cc458

Browse files
authored
Docs: AsNoTracking (#216)
* add asnotracking doc * fix minor issues in example
1 parent c2473b6 commit 37cc458

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

docs/features/asnotracking.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,28 @@ grand_parent: Features
99

1010
# AsNoTracking
1111

12-
TBD
12+
Compatible with:
13+
14+
- [EF Core](https://www.nuget.org/packages/Ardalis.Specification.EntityFrameworkCore/)
15+
- [EF6](https://www.nuget.org/packages/Ardalis.Specification.EntityFramework6/)
16+
17+
The `AsNoTracking` feature applies this method to the resulting query executed by [EF6](https://docs.microsoft.com/en-us/dotnet/api/system.data.entity.dbextensions.asnotracking) or [EF Core](https://docs.microsoft.com/en-us/ef/core/querying/tracking#no-tracking-queries).
18+
19+
> No tracking queries are useful when the results are used in a read-only scenario. They're quicker to execute because there's no need to set up the change tracking information. If you don't need to update the entities retrieved from the database, then a no-tracking query should be used.
20+
21+
## Example
22+
23+
The following example shows how to add `AsNoTracking` to a specification:
24+
25+
```csharp
26+
public class CustomerByNameSpec : Specification<Customer>
27+
{
28+
public CustomerByNameSpec(string name)
29+
{
30+
Query.Where(x => x.Name == name)
31+
.AsNoTracking()
32+
.OrderBy(x => x.Name)
33+
.ThenByDescending(x => x.Address);
34+
}
35+
}
36+
```

0 commit comments

Comments
 (0)