メソッド ベースのクエリ構文例: 要素演算子 (LINQ to Entities)
The examples in this topic demonstrate how to use the First method to query the AdventureWorks Sales Model using method-based query syntax. The AdventureWorks Sales Model used in these examples is built from the Contact, Address, Product, SalesOrderHeader, and SalesOrderDetail tables in the AdventureWorks sample database.
このトピックの例には、次の using/Imports ステートメントが使用されています。
Option Explicit On
Option Strict On
Imports System.Data.Objects
Imports System.Globalization
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using System.Globalization;
using System.Data.EntityClient;
using System.Data.SqlClient;
using System.Data.Common;
First
例
次の例では、First メソッドを使用して、'caroline' で始まる最初の電子メール アドレスを検索します。
Dim name = "caroline"
Using context As New AdventureWorksEntities
Dim contacts As ObjectSet(Of Contact) = context.Contacts
Dim query = contacts.First(Function(cont) _
cont.EmailAddress.StartsWith(name))
Console.WriteLine("An email address starting with 'caroline': {0}", _
query.EmailAddress)
End Using
string name = "caroline";
using (AdventureWorksEntities context = new AdventureWorksEntities())
{
ObjectSet<Contact> contacts = context.Contacts;
Contact query = contacts.First(contact =>
contact.EmailAddress.StartsWith(name));
Console.WriteLine("An email address starting with 'caroline': {0}",
query.EmailAddress);
}