LINQ To SQL:Creating a new entity

EmpDetails Table:

LinqTable.png


Code:


To create a new entity to the EmpDetails table.


using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
LINQ
{
class Program
{
static void Main(string[] args)
{
DataClassesDataContext dc = new DataClassesDataContext();
EmpDetail newEmp = new EmpDetail();
newEmp.Name =
"Ranjith";
newEmp.Location =
"Mumbai";
newEmp.ID = 8;
newEmp.Dept =
"LN";
newEmp.Allowance = 56300;
dc.EmpDetails.InsertOnSubmit(newEmp);
dc.SubmitChanges();
}
}
}