Skip to main content

280 posts tagged with "C#"

C# Programming Language

View All Tags

How to Bind Query String Parameters with AsParameters in a Minimal API

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

A list endpoint collects options: a search term, a category, a sort, a page. Six parameters on one method is hard to read, and passing them along is worse. [AsParameters] puts them in one record, filled from the query string as if each property were its own parameter. This guide uses it on a real product list, with the one detail ASP.NET Core 10 needs.

TypedResults vs Results in ASP.NET Core Minimal APIs

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Results.Ok(x) and TypedResults.Ok(x) put the same response on the wire. The difference is what the rest of your app can see before the request happens. With TypedResults and a declared return type, the OpenAPI document knows every status and body your endpoint can return, without any extra code. Here are both versions of one endpoint, and the documents they produce.

How to Cancel EF Core Queries with a CancellationToken in a Minimal API

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Add a CancellationToken parameter to a minimal API endpoint, pass it to EF Core, and the work can stop when the client goes away. That's the idea, so I measured what it does on MySQL with Oracle's connector. The token fires, and the next step stops. A statement that's already running keeps going until it ends, so the token isn't a substitute for a command timeout.