CSV To C# Model

Login

Email
Password

Don't have an account yet?

Go to Sign up

{{ workbook ? 'Online Table Editor' : 'Input Data' }}
Change File Enter Data
Row Col Row Col
Transpose Clear Delete Empty Deduplicate
ABC abc Abc
Replace
First Row as Header
{{ displayRows.length }} rows x {{ displayHeaders.length }} columns{{ firstRowAsHeader ? ' (1 header)' : '' }} {{ selectedRows.length > 0 ? selectedRows.length + ' selected' : '' }}
Output Data
{{ copied ? 'Copied!' : 'Copy to Clipboard' }} Download File
Properties
Convert CSV to C# Model online — paste, edit, and download C# class.

Namespace:
Class Name:
Access Modifier:
public internal
Property Naming:
PascalCase camelCase Original
Primary Key:
Add [Key] attribute to matching property
Data Annotations:
Add [Key], [Column], [Required] attributes
Nullable Types:
Use int?, DateTime? for nullable columns
Indent:
4 Spaces 2 Spaces Tab
Convert Restart
Insert Row Below
Insert Row Above
Insert Column Right
Insert Column Left
Delete Row {{ contextMenu.row + 1 }}
Delete Column {{ contextMenu.col + 1 }}
Clear Cell
Clear Row
Case sensitive Use regex Cancel Replace All

What Is the CSV to C# Model Converter?

When building .NET applications with Entity Framework, ASP.NET Web API, or any data-driven architecture, you need C# classes (models, entities, DTOs) that mirror your data schema. Writing these classes by hand is repetitive — each column becomes a property with the correct type, and columns headers must be converted to valid C# identifiers.

The CSV to C# Model Converter on A.Tools automates this: upload a CSV file, and the tool produces a complete C# class with auto-typed properties, optional Data Annotations, and configurable naming conventions. Paste the output directly into your .cs file.

All processing runs locally in your browser. No data leaves your device.


Core Features

Automatic Type Inference

The tool examines the data in each column and infers the correct C# type:

Data PatternC# TypeNullable Variant
"Alice", "NYC"stringstring (reference type, always nullable)
30, -5, 0intint?
3.14, 99.99doubledouble?
true, falseboolbool?
2026-05-07, 01/15/2026DateTimeDateTime?
12.50, 0.00 (currency)decimaldecimal?

If a column has mixed types or the tool cannot determine a specific type, it defaults to string.

Namespace and Class Configuration

  • Namespace — Wrap the class in a namespace (e.g., MyApp.Models). Leave empty for no namespace wrapper.

  • Class Name — Set the class name (e.g., Product, UserDto). Defaults to MyClass if empty.

  • Access Modifier — Choose public (accessible from any assembly) or internal (accessible only within the same assembly).

Property Naming Conventions

ConventionCSV HeaderC# Property
PascalCasefirst_nameFirstName
camelCasefirst_namefirstName
Originalfirst_namefirst_name

PascalCase is the C# convention for public properties. camelCase is common for JSON serialization with System.Text.Json. Original preserves the CSV header exactly.

Data Annotations

Enable Data Annotations to add attributes from System.ComponentModel.DataAnnotations:

  • [Column("first_name")] — Maps the property to the original CSV/database column name.

  • [Required] — Marks the property as non-nullable for validation.

  • [Key] — Marks the property as a primary key (when Primary Key is configured).

[Key]

[Column("id")]

public int Id { get; set; }


[Required]

[Column("first_name")]

public string FirstName { get; set; }

Primary Key

Enter a column name in the Primary Key field. The tool adds a [Key] attribute to the matching property, signaling Entity Framework that this is the primary key column.

Nullable Types

Enable Nullable Types to generate nullable value types:

Without nullable:

public int Age { get; set; }

public DateTime CreatedAt { get; set; }

With nullable:

public int? Age { get; set; }

public DateTime? CreatedAt { get; set; }

This is essential when:

  • Your CSV has empty cells in numeric or date columns.

  • You are mapping to database columns that allow NULL.

  • You are using C# 8+ nullable reference types (#nullable enable).

Indentation

Choose between 4 spaces (C# default), 2 spaces, or tab indentation.

Online Table Editor

Edit your data in-browser before converting:

  • Undo / Redo — Full edit history.

  • Add / Delete Rows & Columns — Expand or trim the table.

  • Transpose — Swap rows and columns.

  • Delete Empty — Remove empty rows and columns.

  • Deduplicate — Remove duplicate rows.

  • ABC / abc / Abc — Batch case conversion.

  • Find & Replace — With regex support.

  • First Row as Header — Column headers become C# property names.

Privacy & Security

All processing runs client-side via the browser File API. Files are never uploaded, transmitted, or stored. Safe for database schema metadata, proprietary data models, and production column definitions.


How to Use the CSV to C# Model Generator

Step 1 — Load Your Data

Upload a .csv or .tsv file by dragging it onto the upload area, or click to browse. Alternatively, click Enter Data to type or paste data directly.

Step 2 — Edit Your Data (Optional)

Use the toolbar to refine your data:

  • Add, insert, or delete rows and columns.

  • Transpose the table.

  • Remove empty rows/columns or duplicate rows.

  • Change text case of headers.

  • Find and replace values (supports regex).

  • Toggle First Row as Header to define column names.

Step 3 — Configure C# Properties

In the Properties panel:

OptionWhat to Set
Namespacee.g., MyApp.Models or MyApp.Data.Entities
Class Namee.g., Product, UserDto, OrderViewModel
Access Modifierpublic (default) or internal
Property NamingPascalCase (C# convention) or camelCase (JSON)
Primary KeyColumn name to receive [Key] attribute
Data AnnotationsOn to add [Column], [Required], [Key]
Nullable TypesOn if columns may contain null/empty values
Indent4 spaces (default), 2 spaces, or tab

Step 4 — Convert

Click Convert. The C# class code appears in the Output Data panel.

Step 5 — Copy into Your Project

Click Copy to Clipboard and paste into a new .cs file in your .NET project. Add the required using statements:

using System;

using System.ComponentModel.DataAnnotations;

using System.ComponentModel.DataAnnotations.Schema;


Practical Examples

Example 1: Entity Framework Entity Model

Input CSV:

id,product_name,category,price,stock_count,is_active,created_at

1,Widget A,Hardware,12.99,145,true,2026-01-15

2,Widget B,Hardware,8.50,0,false,2026-02-20

3,Gadget X,Electronics,45.00,23,true,2026-03-10

Settings: Namespace: MyApp.Data.Entities, Class: Product, PascalCase, Primary Key: id, Data Annotations: On, Nullable: On, Indent: 4 Spaces

Output:

namespace MyApp.Data.Entities

{

   public class Product

   {

       [Key]

       [Column("id")]

       public int? Id { get; set; }


       [Required]

       [Column("product_name")]

       public string ProductName { get; set; }


       [Column("category")]

       public string Category { get; set; }


       [Column("price")]

       public double? Price { get; set; }


       [Column("stock_count")]

       public int? StockCount { get; set; }


       [Column("is_active")]

       public bool? IsActive { get; set; }


       [Column("created_at")]

       public DateTime? CreatedAt { get; set; }

   }

}

Example 2: API Response DTO (camelCase)

Input CSV:

userId,userName,email,avatarUrl,lastLogin

101,Alice,[email protected],https://img.example.com/alice.png,2026-05-07

102,Bob,[email protected],,2026-05-06

Settings: Namespace: MyApp.API.DTOs, Class: UserDto, camelCase, Data Annotations: Off, Nullable: On

Output:

namespace MyApp.API.DTOs

{

   public class UserDto

   {

       public int? userId { get; set; }

       public string userName { get; set; }

       public string email { get; set; }

       public string avatarUrl { get; set; }

       public DateTime? lastLogin { get; set; }

   }

}

Example 3: Minimal Model (No Annotations)

Input CSV:

name,email,role

Alice,[email protected],Admin

Bob,[email protected],Editor

Settings: Class: User, PascalCase, No namespace, No annotations, No nullable

Output:

public class User

{

   public string Name { get; set; }

   public string Email { get; set; }

   public string Role { get; set; }

}


Understanding C# Model Concepts

Models, Entities, and DTOs

TermPurposeExample
EntityMaps to a database table (EF Core)Product, Order
DTOData Transfer Object for API input/outputProductDto, OrderResponse
ViewModelShape data for a specific view/pageProductListViewModel
POCOPlain Old CLR Object — simple class with propertiesAny of the above

This tool generates POCOs that can serve as any of these, depending on how you configure the options.

C# Auto-Properties

The tool generates C# auto-implemented properties:

public string Name { get; set; }

This is the standard C# shorthand for a property with a backing field. The { get; set; } syntax was introduced in C# 3.0 and is the idiomatic way to define data classes. See Microsoft Learn — Properties.

Data Annotations in Entity Framework

Entity Framework uses Data Annotations as convention-based configuration:

  • [Key] — Specifies the primary key.

  • [Column("db_column_name")] — Maps a property to a specific database column name.

  • [Required] — Makes the column NOT NULL in the database and adds validation.

These attributes come from System.ComponentModel.DataAnnotations and System.ComponentModel.DataAnnotations.Schema.

When to Use Nullable Types

Enable nullable types when:

  • Your CSV data has empty cells in numeric, date, or boolean columns.

  • You are generating models for database tables with nullable columns.

  • Your project uses C# 8+ nullable reference types (#nullable enable).

Entity Framework Conventions

When using the generated class with EF Core:

  • Properties named Id or <ClassName>Id are automatically detected as primary keys.

  • The [Key] attribute overrides this convention.

  • PascalCase property names are converted to snake_case or other conventions by EF's column naming strategy.


Frequently Asked Questions (FAQ)

  • Is my CSV data uploaded to a server?

    No. All file processing happens entirely in your browser using JavaScript. Your CSV data is never uploaded, transferred, or stored on any server.

  • How does the tool determine C# data types?

    The tool analyzes the actual data values in each CSV column. If all values are whole numbers, it uses int. If values contain decimal points, it uses double. If values match date patterns, it uses DateTime. Boolean values (true/false) map to bool. Everything else defaults to string.

  • What are Data Annotations?

    Data Annotations are C# attributes from System.ComponentModel.DataAnnotations that add metadata to class properties. The tool generates [Key] for primary keys, [Column("name")] for column mapping, and [Required] for non-nullable validation. These are used by Entity Framework, ASP.NET Model Validation, and API formatters.

  • What does the Primary Key option do?

    Enter the exact name of a CSV column. The tool adds a [Key] attribute to the corresponding C# property, which tells Entity Framework that this property is the primary key for the database table.

  • What is the difference between PascalCase and camelCase?

    PascalCase capitalizes the first letter of each word: FirstName, StockCount. This is the C# convention for public properties and is the default for Entity Framework. camelCase lowercases the first word: firstName, stockCount. This is common for JSON serialization with System.Text.Json and JavaScript interop.

  • What does Nullable Types do?

    When enabled, value types (int, double, DateTime, bool) are generated as nullable (int?, double?, DateTime?, bool?). This allows the property to hold a null value, which is necessary when your CSV has empty cells or your database columns allow NULL.

  • What file formats are supported?

    The tool accepts .csv (comma-separated values) and .tsv (tab-separated values) files. You can also enter data manually through the built-in table editor.

  • Is there a row limit?

    Type inference uses only the first row of data to determine column types. The class definition itself depends only on column headers (one property per column), so there is no practical limit on the number of data rows.

Featured Tools

Featured tools that you might find useful.

Popular Tools

List of popular tools that users love and frequently use.

New Tools

The latest tools added to our collection, designed for you.

Topics

The tools grouped by topics to quickly find what you need.
Free online Excel to JSON converter. Transform XLSX, XLS, XLSM files into JSON arrays, objects, or keyed formats instantly in your browser — no upload, 100% private.

Excel To JSON

Free online Excel to JSON converter. Transform XLSX, XLS, XLSM files into JSON arrays, objects, or keyed formats instantly in your browser — no upload, 100% private.
Free Excel to CSV converter. Convert XLSX, XLS, XLSM to CSV instantly in your browser. No upload, 100% private. Edit, transpose, deduplicate before exporting.

Excel To CSV

Free Excel to CSV converter. Convert XLSX, XLS, XLSM to CSV instantly in your browser. No upload, 100% private. Edit, transpose, deduplicate before exporting.
Free online Excel to SQL converter. Generate CREATE TABLE and INSERT statements from spreadsheets for MySQL, PostgreSQL, SQLite, and SQL Server. Supports batch insert, primary keys, and type inference.

Excel To SQL

Free online Excel to SQL converter. Generate CREATE TABLE and INSERT statements from spreadsheets for MySQL, PostgreSQL, SQLite, and SQL Server. Supports batch insert, primary keys, and type inference.
Free online Excel to ASCII table converter with 10 border styles (MySQL, Unicode, reStructuredText, and more). Add code comment wrappers in 8 languages. Supports text alignment. Client-side processing.

Excel To ASCII Table

Free online Excel to ASCII table converter with 10 border styles (MySQL, Unicode, reStructuredText, and more). Add code comment wrappers in 8 languages. Supports text alignment. Client-side processing.