How to: Return a Single Object
This topic provides an example of how to return a single Customer object.
To run the code in this example, you need a fluent model based on the Northwind database.
The following code is the LINQ example.
using ( FluentModel dbContext = new FluentModel() )
{
Customer customer = ( from c in dbContext.Customers
where c.Country == "Germany"
select c ).FirstOrDefault();
if ( customer != null )
Console.WriteLine( "CustomerID: {0}", customer.CustomerID );
}
Using dbContext As New FluentModel()
Dim _customer As Customer = (
From c In dbContext.Customers
Where c.Country = "Germany"
Select c).FirstOrDefault()
If _customer IsNot Nothing Then
Console.WriteLine("CustomerID: {0}", _customer.CustomerID)
End If
End Using