Skip to content

Commit

Permalink
feat: Exibe logs do EF no console
Browse files Browse the repository at this point in the history
  • Loading branch information
renebentes committed Oct 6, 2022
1 parent 0510fa5 commit 2459145
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Blog/Data/BlogDataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ public class BlogDataContext : DbContext
public DbSet<User> Users { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlServer("Server=localhost,1433;Database=Blog;User ID=sa;Password=1q2w3e4r@#$;Trusted_Connection=False;TrustServerCertificate=True;");
{
options.UseSqlServer("Server=localhost,1433;Database=Blog;User ID=sa;Password=1q2w3e4r@#$;Trusted_Connection=False;TrustServerCertificate=True;");
options.LogTo(Console.WriteLine);
}
}
3 changes: 1 addition & 2 deletions Blog/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
.AsNoTracking()
// Efetua o JOIN
.Include(p => p.Author)
.Include(p => p.Category)
.OrderByDescending(p => p.LastUpdateDate)
.ToList();

foreach (var post in posts)
{
Console.WriteLine($"{post.Title} escrito por {post.Author?.Name}");
}


0 comments on commit 2459145

Please sign in to comment.