LINQ(Language Integrated Query)는 모든 유형의 데이터 소스(메모리 내 객체, 데이터베이스, XML 문서 등)를 쿼리 하도록 통합되어 있으며,. NET Framework 버전 3.5에 추가되어 개체와 데이터 사이의 연결을 자유롭게 제공하였습니다.
Download .NET Framework | Free official downloads
Downloads for building and running applications with .NET Framework. Get web installer, offline installer, and language pack downloads for .NET Framework.
dotnet.microsoft.com
SQL, XML등의 쿼리 언어에 대한 지식이 없어도, C# 또는 Visual Basic 프로그래밍 언어를 아신다면 쿼리를 작성할 수 있습니다.
간단한 예제로 워밍업을 해보도록 할까요!!
using System;
using System.Linq;
class Program {
static void Main() {
string[] words = {"hello", "wonderful", "LINQ", "beautiful", "world"};
//단어의 글자수가 5보다 작거나 같은 것만 가져오기
var shortWords = from word in words where word.Length <= 5 select word;
//Linq 된 단어를 나타내기
foreach (var word in shortWords) {
Console.WriteLine(word);
}
Console.ReadLine();
}
}
Linq 구문을 Sql 쿼리 문으로 해석해 보면
-- words 테이블의 word 필드에서 글자수(길이)가
-- 5보다 작거나 같은 것을 가져오기
-- MS-SQL
SELECT
word
FROM words
WHERE LEN(word) <= 5
-- ORACLE
SELECT
word
FROM words
WHERE LENGTH(word) <= 5
간단하죠