![]() You can use DTO objects, as we did in our ASP.NET Core Web API project, but this is a faster solution and serves the purpose (we are not saying this is a better approach, just as opposite). This is the protection for the “Self-referencing loop” error while returning the result from our API (which does happen in real-world projects). AddNewtonsoftJson(o => o.SerializerSettings.ReferenceLoopHandling = Options => options.MigrationsAssembly("EFCoreApp"))) Opts.UseSqlServer(Configuration.GetConnectionString("sqlConnection"), Public void ConfigureServices(IServiceCollection services) Learning Web API? Get our eBook ASP.NET Core Web API Best Practices and become an expert for FREE! > GET THE BOOK e.Evaluations)īefore we send request to execute this query, we should install the library and modify the Startup.cs class: There are different approaches to retrieve our data: For now, just know that EF Core won’t track changes (when we apply AsNoTracking) on the loaded entity which will speed up the query execution:ĭifferent Ways of Building Relational Queries In the next article, we are going to talk about how EF Core modifies data in the database and track changes in the loaded entity. TIP: When we write only read-only queries in Entity Framework Core(the result of the query won’t be used for any additional database modification), we should always add AsNoTracking method to speed up the execution. Finally, we have ToList() method which executes this query. Where(s => s.Age > 25)“ is a second part of the query where we use a LINQ command to select only required rows. The “ _context.Students” is the first part where we access the Student table in the database via the DbSet Students property. From this query, we can see all the mentioned parts.
0 Comments
Leave a Reply. |