LINQ (Language Integrated Query) is a Microsoft programming model and methodology that essentially adds formal query capabilities into Microsoft .NET-based programming languages. LINQ offers a compact, expressive, and intelligible syntax for manipulating data.
SQL is a Structured Query Language used to save and retrieve data from a database. In the same way, LINQ is a structured query syntax built in C# and VB.NET used to save and retrieve data from different types of data sources like an Object Collection, SQL server database, XML, web service etc.
Why use LINQ
In this artical Introduction to LINQ.It is a groundbreaking innovation in Visual Studio 2008 and the .NET Framework version 3.5 that bridges the gap between the world of objects and the world of data. You can use LINQ queries.
Introduced in Visual Studio 2008 LINQ (Language Integrated Query) allows writing queries even without the knowledge of query languages like SQL, XML etc. LINQ queries can be written for diverse data types.Using linq query with lamda expression.
SQL is a Structured Query Language used to save and retrieve data from a database. In the same way, LINQ is a structured query syntax built in C# and VB.NET used to save and retrieve data from different types of data sources like an Object Collection, SQL server database, XML, web service etc.
Why use LINQ
- Using LINQ reduces the amount of code to be written as compared with a more traditional approach. Using LINQ provides type checking of objects at compile time.
- Using makes the code more readable so other developers can easily maintain and understand it.
- Using LINQ provides IntelliSense for generic collections.
- Developers don’t have to learn a new query language for each type of data format.
In this artical Introduction to LINQ.It is a groundbreaking innovation in Visual Studio 2008 and the .NET Framework version 3.5 that bridges the gap between the world of objects and the world of data. You can use LINQ queries.
Introduced in Visual Studio 2008 LINQ (Language Integrated Query) allows writing queries even without the knowledge of query languages like SQL, XML etc. LINQ queries can be written for diverse data types.Using linq query with lamda expression.
Example
public ActionResult LinqEx()
{
string[] Linqwords = {"Hi", "This", "is", "Testing", "Of linq","Example"
}; //Get only short words
var shortLinq = from word in Linqwords where word.Length <= 6 select word;
//Print each word out
foreach (var word in shortLinq)
{
var printword += word
}
ViewBag.Data= printword
return View();
}
Note- In this example We create a controller and create a method actionresult type
LinqEx name and define a string array and apply simple linq query.
{
string[] Linqwords = {"Hi", "This", "is", "Testing", "Of linq","Example"
}; //Get only short words
var shortLinq = from word in Linqwords where word.Length <= 6 select word;
//Print each word out
foreach (var word in shortLinq)
{
var printword += word
}
ViewBag.Data= printword
return View();
}
Syntax of LINQ
There are two syntaxes of LINQ. These are the MEntion below like-Lamda (Method) Syntax
Example
var LinqWord = Linqwords.Where( w => w.length > 10);
Note- In this example => is denoted lamda Expression
Query (Comprehension) Syntax
Example
var LinqWord = from w in words where w.length > 10;
Note- In this example use linq Query
USE AUTOINCREMENT ID IN SQL SERVER
In this articale show auto increment column in table we usallycreated table then give id identity then
What is meaning and why we use? describe in exmple like-
Result-
Use This Steps In Result-
1. Create Table With Create Query.
2. Insert Data With Insert Query.
3. Show Table Data Through Select Query in Sql Server.
The following SQL statement defines the "ID" column to be an auto-increment primary key field in the "Category" table (Given Category is Table Name and CategoryId And CategoryName are Field in Table
Create table Category
Create table Category
(
CategoryId INT IDENTITY(1,1) Primary Key,
CategoryName NVARCHAR(100)
)
USE IDENTITY(1,1) in Table =
Where the 1,1 is the starting number is 1 and increment by 1 that's the resigon You can use Identity(1,1)
In the example above, the starting value for IDENTITY is 1, and it will increment by 1 for each new record.
Exp. To specify that the "ID" column should start at value 10 and increment by 5, change it to IDENTITY(10,5).
In This Following Image CategoryId Is Auto Increment And Id id Start with 1 and It Will
Increment By 1
1. Create Table With Create Query.
2. Insert Data With Insert Query.
3. Show Table Data Through Select Query in Sql Server.
0 comments :
Post a Comment