Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
De voorbeelden in dit onderwerp laten zien hoe u de methode First gebruikt om een query uit te voeren op het AdventureWorks Sales Model met behulp van een querysyntaxis op basis van een methode. Het AdventureWorks Sales Model dat in deze voorbeelden wordt gebruikt, is gebaseerd op de tabellen Contact, Adres, Product, SalesOrderHeader en SalesOrderDetail in de voorbeelddatabase AdventureWorks.
In het voorbeeld in dit onderwerp worden de volgende using/Imports uitspraken gebruikt:
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;
Option Explicit On
Option Strict On
Imports System.Data.Objects
Imports System.Globalization
Eerste
Voorbeeld
In het volgende voorbeeld wordt de methode First gebruikt om het eerste e-mailadres te vinden dat begint met 'caroline'.
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': {query.EmailAddress}");
}
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