-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Desabilita rastreamento de objetos do EF
- Loading branch information
1 parent
2cf8ca9
commit a3504ca
Showing
1 changed file
with
16 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
using Blog.Data; | ||
|
||
using var context = new BlogDataContext(); | ||
|
||
var tags = context | ||
.Tags | ||
// Filtro antes da execução | ||
.Where(it => it.Name.Contains(".NET")) | ||
// Executa a query no banco | ||
.ToList(); | ||
|
||
foreach (var tag in tags) | ||
{ | ||
Console.WriteLine(tag.Name); | ||
} | ||
using Blog.Data; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
using var context = new BlogDataContext(); | ||
|
||
var tags = context | ||
.Tags | ||
// Desabilita metadados de traqueamento (referências entre os objetos) | ||
// Usar somente em modo de leitura, nunca com operações de escrita | ||
.AsNoTracking() | ||
.ToList(); | ||
|
||
foreach (var tag in tags) | ||
{ | ||
Console.WriteLine(tag.Name); | ||
} |