Export (0) Print
Expand All

Method-Based Query Syntax Examples: Element Operators

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.

The example in this topic uses the following using/Imports statements:


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

Example

The following example uses the First method to find the first e-mail address that starts with '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': {0}",
query.EmailAddress);
}
    

See Also




Build Date:

2012-10-01
Show:
© 2014 Microsoft