시작

LINQ to SQL을 사용하면 메모리 내 컬렉션에 액세스하는 것처럼 LINQ 기술을 사용하여 SQL 데이터베이스에 액세스할 수 있습니다.

예를 들어 다음 코드에서 nw 개체는 Northwind 데이터베이스를 나타내기 위해 만든 것으로 Customers 테이블을 대상으로 열은 Customers에서 London가 필터링되고 CompanyName에 대한 문자열은 검색용으로 선택됩니다.

루프가 실행되면 CompanyName 값의 컬렉션이 검색됩니다.

// Northwnd inherits from System.Data.Linq.DataContext.
Northwnd nw = new Northwnd(@"northwnd.mdf");
// or, if you are not using SQL Server Express
// Northwnd nw = new Northwnd("Database=Northwind;Server=server_name;Integrated Security=SSPI");

var companyNameQuery =
    from cust in nw.Customers
    where cust.City == "London"
    select cust.CompanyName;

foreach (var customer in companyNameQuery)
{
    Console.WriteLine(customer);
}
' Northwnd inherits from System.Data.Linq.DataContext.
Dim nw As New Northwnd("c:\northwnd.mdf")
' or, if you are not using SQL Server Express
' Dim nw As New Northwnd("Database=Northwind;Server=dschwart7;Integrated Security=SSPI")

Dim companyNameQuery = _
    From cust In nw.Customers _
    Where cust.City = "London" _
    Select cust.CompanyName

For Each customer In companyNameQuery
    Console.WriteLine(customer)
Next

다음 단계

삽입 및 업데이트를 포함한 몇 가지 추가 예는 LINQ to SQL로 수행할 수 있는 작업을 참조하세요.

다음으로, LINQ to SQL 사용에 대한 실습 환경을 갖기 위해 몇 가지 연습 및 자습서를 시도합니다. 연습을 통한 학습을 참조하세요.

마지막으로 LINQ to SQL 사용을 위한 일반적인 단계를 읽고 고유의 LINQ to SQL 프로젝트를 시작하는 방법을 알아봅니다.

참고 항목