SQL to C#: models from a DDL script
What follows is not a mock-up: it is the real output of the generator for the script on the left. You get the same code in the editor under “Codegen → C#”.
The inputschema.sql
CREATE TABLE users (
id BIGINT NOT NULL PRIMARY KEY,
email VARCHAR(255) NOT NULL UNIQUE,
full_name VARCHAR(120),
is_active BOOLEAN NOT NULL,
created_at TIMESTAMP NOT NULL
);
CREATE TABLE orders (
id BIGINT NOT NULL PRIMARY KEY,
user_id BIGINT NOT NULL REFERENCES users(id),
total DECIMAL(12,2) NOT NULL,
note TEXT,
placed_at TIMESTAMP NOT NULL
);What comes outModels.cs
using System;
public sealed class Users
{
public long Id { get; set; }
public string Email { get; set; } = null!;
public string? FullName { get; set; }
public bool IsActive { get; set; }
public DateTime CreatedAt { get; set; }
}
public sealed class Orders
{
public long Id { get; set; }
public long UserId { get; set; } // → users.id
public decimal Total { get; set; }
public string? Note { get; set; }
public DateTime PlacedAt { get; set; }
}Open the editor
The script stays in the browser: both parsing and generation run on your machine, nothing goes to a server.
How the types land
| in SQL | in the model |
|---|---|
BIGINT | long |
VARCHAR(255) | string |
BOOLEAN | bool |
TIMESTAMP | DateTime |
DECIMAL(12,2) | decimal |
TEXT | string? |
- Optional field
string?- Column name
FullName- Relation
// → users.id