---
title: "How to insert data by using LINQ to SQL concept"  
description: "How to insert data by using LINQ to SQL concept"  
author: "Ashutosh Patel"  
published: 2025-03-24  
updated: 2025-04-20  
canonical: https://www.mindstick.com/forum/161348/how-to-insert-data-by-using-linq-to-sql-concept  
category: "linq"  
tags: ["linq", "sql server", "linq to sql"]  
reading_time: 2 minutes  

---

# How to insert data by using LINQ to SQL concept

How to [insert data](https://www.mindstick.com/forum/33964/insert-data-in-datagridview-from-text-box-c-sharp) by using [LINQ to SQL](https://www.mindstick.com/articles/338528/how-to-use-linq-to-sql-select-query-using-c-sharp) [concept](https://www.mindstick.com/blog/79/routing-concept-in-dot-net)

## Replies

### Reply by Khushi Singh

When working with LINQ to [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) in C#, [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) insertion requires proper implementation of data context alongside mapped classes. The C# classes and LINQ queries enable LINQ to SQL to automatically perform database table mapping for CRUD operations.

The process of data insertion with LINQ to SQL functions as follows:

## Step-by-Step Overview (Theory)

**Create a DataContext**: This represents your database and handles the connection.

**Define Entity Classes**: These are mapped to your database tables using the Object Relational Designer (DBML file).

**Create an Object:** Instantiate the entity class and populate its properties with data.

**[Insert](https://www.mindstick.com/blog/173/executing-insert-delete-or-update-query-in-sqlserver-using-ado-dot-net) the Object:** Use the `InsertOnSubmit()` method on the corresponding table.

**Submit Changes**: Call `SubmitChanges()` on the `DataContext` to push the new record into the database.

## Code Example

```cs
using (MyDataContext db = new MyDataContext())
{
   // Create a new record
   Student newStudent = new Student();
   newStudent.Name = "John Doe";
   newStudent.Age = 22;
   newStudent.Email = "john.doe@example.com";
   // Add the object to the Students table
   db.Students.InsertOnSubmit(newStudent);
   // Commit the insert to the database
   db.SubmitChanges();
}
```

This example uses `MyDataContext` as the LINQ to SQL data context which came from a .dbml file and Student represents the table-mapped class. The insertion sequence requires you to create a Student object with value assignments followed by a call to `SubmitChanges()` to implement the changes.


---

Original Source: https://www.mindstick.com/forum/161348/how-to-insert-data-by-using-linq-to-sql-concept

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
