Wriju's BLOG

.NET, Cloud and everything

LINQ to SQL : Writing DML query to perform quick operation

In LINQ to SQL you also can send the DML query to perform the quick database modification.


Caution!!! It is not recommended as it does not support object model so has no compile time checking.


static void Main(string[] args)


    string strConnection = @”Data Source=wriju-orcas\sqlexpress;Initial Catalog=TestDB;”;


    TestDB db = new TestDB(strConnection);


    //To check the SQL query

    db.Log = Console.Out;



    db.ExecuteCommand(“INSERT INTO Emp(Name) VALUES(‘Wriju’)”, “”);



    db.ExecuteCommand(“DELETE FROM Emp WHERE Id = 19”, “”);



    db.ExecuteCommand(“UPDATE Emp SET Name = ‘A’ WHERE Id = 21”, “”);


    //Check the rows inside table