C# and SQL Server Data Type Mapping: Complete Guide
Hello everyone! I'm a beginner C# developer writing a small application for working with SQL Server database via Entity Framework. I've encountered a problem: I can't exactly understand which C# data types correspond to which SQL Server types.
\n\nFor example, I have a table with columns:
\nCREATE TABLE Users (\n Id INT PRIMARY KEY,\n Name NVARCHAR(100),\n Salary DECIMAL(18,2),\n IsActive BIT,\n CreatedAt DATETIME2\n);\n\nIn C# I'm creating a model:
\npublic class User\n{\n public int Id { get; set; } // INT -> int, this seems clear\n public string Name { get; set; } // NVARCHAR -> string, also clear\n public decimal Salary { get; set; } // DECIMAL -> decimal?\n public bool IsActive { get; set; } // BIT -> No answers yet.
Log in to leave an answer