Data Access has been discontinued. Please refer to this page for more information.

How to: Return a Single Object

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

This topic provides an example of how to return a single Customer object.

To run the code in this example, you need to create a new Telerik Data Access Domain Model based on the Northwind database.

The following code is the LINQ example.

using ( EntitiesModel dbContext = new EntitiesModel() )
{
   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 EntitiesModel()
 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

See Also