Skip to main content

290 posts tagged with ".NET"

.NET Framework and Core for Application Development

View All Tags

How to Read Rows from MySQL with EF Core and LINQ

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

With EF Core, you read rows by writing a LINQ query in C#, and EF Core turns it into SQL. The part that surprises people is timing: building the query sends nothing, and only ToListAsync or a similar call goes to MySQL. This guide reads rows with Where and OrderBy, shows the SQL each piece becomes, and proves the timing with real logs.

How to Send API Requests from a .http File in VS Code and Visual Studio

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

A .http file is a plain text file that holds API requests. It lives next to your code and goes into Git with it, so everyone on the team has the same requests. VS Code with the free REST Client extension and Visual Studio both add a link above each request that sends it. This guide covers the format and how to send requests in each editor.

Fixed: "Body was inferred but the method does not allow inferred body parameters" in a Minimal API

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

After I added one small GET endpoint, every request to my minimal API answered 500, health checks included. The log said Body was inferred but the method does not allow inferred body parameters. The endpoint took a record as a parameter, and ASP.NET Core assumes that comes from the JSON body, which GET doesn't get. [AsParameters] tells it to read the query string instead.

Fixed: "Cannot resolve scoped service 'InventoryDbContext' from root provider" in ASP.NET Core

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

I wanted to read something from the database once, while the app started, so I asked app.Services for the DbContext in Program.cs. The app crashed: Cannot resolve scoped service 'Dewiride.Inventory.Data.InventoryDbContext' from root provider. Scoped services need a scope, and at startup there's no request to provide one. You can create one yourself in two lines.

Fixed: "Cannot consume scoped service 'DbContextOptions' from singleton" in ASP.NET Core

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

My API refused to start: Cannot consume scoped service 'Microsoft.EntityFrameworkCore.DbContextOptions1[…InventoryDbContext]' from singleton 'Dewiride.Inventory.Api.CategoryCache'.A small cache class, registered as a singleton, asked for theDbContext. A singleton lives as long as the app, and a DbContextbelongs to one request, so ASP.NET Core stops it.IServiceScopeFactory` is the way for a singleton to use one.