Entity Framework Core Tutorial 기본 쿼리
Entity Framework Core는 LINQ (언어 통합 쿼리)를 사용하여 데이터베이스의 데이터를 쿼리합니다.
- LINQ를 사용하면 C # (또는 선택한 .NET 언어)을 사용하여 파생 된 컨텍스트 및 엔터티 클래스를 기반으로 강력한 형식의 쿼리를 작성할 수 있습니다.
- Entity Framework의 쿼리 코어는 EF 6에서와 마찬가지로 데이터베이스에서 엔터티를로드합니다.
- 더 최적화 된 SQL 쿼리와 C # / VB.NET 함수를 LINQ-to-Entities 쿼리에 포함 할 수있는 기능을 제공합니다.
세 개의 엔티티가 포함 된 간단한 모델이 있다고 가정 해 보겠습니다.
public class Customer { public int CustomerId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Address { get; set; } public virtual List<Invoice> Invoices { get; set; } }
모든 데이터로드
다음 예제에서는 Customers
테이블의 모든 데이터를로드합니다.
using (var context = new MyContext()) { var customers = context.Customers.ToList(); }
단일 엔터티로드
다음 예에서 단일 레코드로드 Customers
을 기반으로 테이블에 CustomerId
.
using (var context = new MyContext()) { var customers = context.Customers .Single(c => c.CustomerId == 1); }
데이터 필터링
다음 예제에서는 FirstName
표시가있는 모든 고객을로드합니다.
using (var context = new MyContext()) { var customers = context.Customers .Where(c => c.FirstName == "Mark") .ToList(); }