Which is a recommended practice when using DTOs and AutoMapper in ASP.NET Core?
4 phương ánCó giải thíchKhó
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Khi sử dụng DTOs và AutoMapper trong ASP.NET Core, một thực hành được khuyến nghị là trả về DTOs từ các controller thay vì các thực thể EF. Điều này giúp phân tách logic kinh doanh khỏi logic của ứng dụng và cải thiện bảo mật. Việc trả về DTOs cũng giúp giảm thiểu rủi ro bị tấn công bằng cách inject các thực thể EF vào các controller. Ngoài ra, việc sử dụng DTOs giúp dễ dàng thay đổi cấu trúc dữ liệu mà không ảnh hưởng đến các controller. Điều này giúp tăng cường khả năng mở rộng và bảo trì của ứng dụng.
Cùng chương 2
Consider this EF Core entity: public class User { public int Id { get; set; } public string Username { get; set; } = String.Empty; public string HashedPassword { get; set; } = String.Empty; public bool IsAdmin { get; set; } } Which of the following would be an appropriate DTO to return to a client asking for user details?Có lời giảiCâu hỏiIn a .NET 9 application using EF Core, you've defined the following DbContext. How does EF Core know which classes to include in the database model? public class ApplicationDbContext : DbContext { public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { } public DbSet<Product> Products { get; set; } public DbSet<Category> Categories { get; set; } }Có lời giảiCâu hỏiThe following LINQ query is written in a .NET 8 service using EF Core. What does it do? var result = await _context.Products .Where(p => p.IsAvailable) .OrderBy(p => p.Name) .ToListAsync();Có lời giảiCâu hỏiCả 8 câu của chủ đề8 câu