Skip to main content

280 posts tagged with "C#"

C# Programming Language

View All Tags

How to Create a Unique Index with EF Core and MySQL

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

Some values must never repeat: a product's SKU, a category's name, a user's email. Checking in code isn't enough, because two requests at the same moment can both pass the check. A unique index makes the database refuse the second one. This guide adds two from EF Core's model, applies them to MySQL 9.7, and shows what MySQL treats as a duplicate, which isn't always what you'd expect.

How to Add a CHECK Constraint with EF Core and MySQL

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

Validation in your API stops most bad data, but not data from a script, a second app, or a bug that skips the validation. A CHECK constraint makes the database itself refuse a row that breaks a rule, such as a negative price. This guide adds three to a products table from EF Core's model, applies them with a migration, and proves MySQL enforces them on both inserts and updates.

How to Save and Read DateTime as UTC with EF Core and MySQL

· 9 min read
Jagdish Kumawat
Founder @ Dewiride

You save DateTime.UtcNow with EF Core, read it back from MySQL, and the Z that marks UTC is gone from your API's JSON. Worse, a DateTime.Now slipped in somewhere is stored as local time, hours away from everything else. This guide shows both problems with a real .NET C# Web API and MySQL 9.7, explains why they happen, and fixes them for every DateTime in the model with one small value converter.

How to Set Decimal Precision for Money with EF Core and MySQL

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

Money belongs in a decimal, never a double, and the database column needs a precision you chose on purpose. This guide shows what MySQL column EF Core creates for a decimal when you don't configure it, how MySQL handles values that don't fit, and the three ways to set the precision: one property, an attribute, or one rule for every decimal in the model.

How to Store an Enum as a String with EF Core and MySQL

· 10 min read
Jagdish Kumawat
Founder @ Dewiride

By default, EF Core saves a C# enum as its number: Sale becomes 2. That works, but anyone reading the table needs the C# code to know what 2 means, and reordering the enum silently changes the meaning of every old row. This guide stores enums as their names instead, first for one property and then for every enum at once, and handles the part most guides skip: the rows that already hold numbers.

How to Run a Single C# File with dotnet run (.NET 10 File-Based Apps)

· 9 min read
Jagdish Kumawat
Founder @ Dewiride

Until .NET 10, even a three-line C# program needed a project file. Now dotnet run hello.cs runs a single .cs file directly, and a line at the top can pull in NuGet packages. It's perfect for small tools and quick tests, like checking that a database connection string works. This guide writes one, adds a package, shows where .NET builds it, and turns it into a normal project when it outgrows one file.

How to Write a MySQL Connection String for .NET C#

· 11 min read
Jagdish Kumawat
Founder @ Dewiride

Every .NET C# app that talks to MySQL starts with a connection string: one line that says where the server is, which database to use, who you are, and how to protect the connection. This guide builds one for Oracle's MySql.Data driver, which EF Core's MySql.EntityFrameworkCore provider also uses, explains each key with its documented default, and tests it with a small C# program that tells you exactly how it connected.

How to Pin the .NET SDK Version with global.json in a .NET C# Project

· 10 min read
Jagdish Kumawat
Founder @ Dewiride

By default, every dotnet command uses the newest .NET SDK on the computer. That's fine until a teammate or a build server has a different one, and the same project starts behaving differently. A global.json file at the root of your repository settles which SDK the project uses. This guide creates one with .NET 10, then tries every rollForward value against the real SDK installed on this computer, so you can see which ones pass and which fail before you choose.

How to Check Which .NET SDKs and Runtimes Are Installed for C# Development

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

Before you create or build a C# project, it helps to know which .NET versions your computer has. One dotnet command answers each question: which SDK your project will use, which SDKs and runtimes are installed, and whether any of them needs an update. This guide runs each one on a Mac with .NET 10 and explains every line of output.

How to Install dotnet-ef as a Local Tool in a .NET C# Project

· 14 min read
Jagdish Kumawat
Founder @ Dewiride

dotnet ef, the command-line tools for Entity Framework Core, is usually installed once for the whole computer. Installed as a local tool instead, it's pinned to an exact version in a small file inside your repository, so every developer and every build machine runs the same version as the project's EF Core packages. This guide installs it that way with .NET 10, shows every command's real output, and adds the one package the tools need in your project.