Basic LinQ to SQL

Need To Write This Blog

I am a newbie in asp .net and this is my first article on c-sharpcorner.com. I know my English is not very good but I am trying my best. Coming to my article’s topic; I have been working on one project for the last three months. In this project, a huge number of queries such as searching a database, uploading a file, creating a user, deleting a user and so on is required. After doing all the queries with the help of the Store Procedure, which is time consuming, I heard about the linq. And I started searching about it on Google. It’s very easy and is suitable for a beginner Developer. So, I moved from the Store Procedure to the Linq Query. According to me this is great. One may have doubts about the linq, you may think, how’s it possible, how does this simplify the work? But this is a reality, let me show you the comparison table, given below, to understand.

 
Compare Store Procedure Query And Linq Query
 
Store Procedure Query Linq Query

ALTER proc [dbo].[select_records]
as
Select
* from Table_1
Return

Funcation name call Store Procedure

public DataTable _State()

{

    dd._cmd = new SqlCommand("Store Procedure Name ", “Connection String Name”);

    dd._cmd.CommandType = CommandType.StoredProcedure;

    return _DAL.Dal._DataTable(dd._cmd, dd._con);

}

dataGridView.DataSource = _state();

Make object DataContext class like that

DataClasses1DataContext db = new DataClasses1DataContext();
State st = new State();
dataGridView1.DataSource = from temp in db.st select temp;

 

 

 

 

A simple Query will clear all the doubts about who is the best. Let’s assume we have to show simple Table on the DataGridView in Windows Application. The state Records show in dataGridView.

Advantages L2S Offers

  • No magic strings, like you have in SQL queries
  • Intellisense
  • Compile check when database changes
  • Faster development
  • Unit of work pattern (context)
  • Auto-generated domain objects that are usable in small projects
  • Lazy loading
  • Learning to write the linq queries/lambdas is a must for the .NET developers

Basic Concept Of Linq


 
Relation In Data Table In Linq Class