다음을 통해 공유


시작하기

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 프로젝트를 시작하는 방법을 알아봅니다.

참고하십시오