DatabaseColumn
Represents a database column with its metadata
public sealed record DatabaseColumn : IEquatable<DatabaseColumn>
Example
// Create a column definition
var column = new DatabaseColumn
{
Name = "Id",
SqlType = "uniqueidentifier",
CSharpType = "Guid",
IsNullable = false,
IsPrimaryKey = true,
IsIdentity = false,
IsComputed = false
};
// Create a string column with max length
var nameColumn = new DatabaseColumn
{
Name = "Name",
SqlType = "nvarchar(100)",
CSharpType = "string",
IsNullable = false,
MaxLength = 100
};
Properties
Name
public string Name { get; init; }
Column name
SqlType
public string SqlType { get; init; }
SQL data type (e.g., "int", "varchar(50)", "decimal(10,2)")
CSharpType
public string CSharpType { get; init; }
Corresponding C# type (e.g., "int", "string", "decimal")
IsNullable
public bool IsNullable { get; init; }
Whether the column allows null values
IsPrimaryKey
public bool IsPrimaryKey { get; init; }
Whether the column is part of the primary key
IsIdentity
public bool IsIdentity { get; init; }
Whether the column is an identity/auto-increment column
IsComputed
public bool IsComputed { get; init; }
Whether the column is computed
MaxLength
public int? MaxLength { get; init; }
Maximum length for string columns
Precision
public int? Precision { get; init; }
Precision for decimal columns
Scale
public int? Scale { get; init; }
Scale for decimal columns