Comparison Expression
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.
A comparison expression checks whether a constant value, a property value, or a method result is equal, not equal, greater than, or less than another value. All comparisons, both implicit and explicit, require that all components are comparable in the data source. Comparison expressions are frequently used in Where clauses for restricting the query results.
The following example in query expression syntax shows a query that returns results where the customer country is equal to "Germany":
using ( EntitiesModel dbContext = new EntitiesModel() )
{
IQueryable<Customer> customers = from customer in dbContext.Customers
where customer.Country == "Germany"
select customer;
foreach ( Customer c in customers )
{
Console.WriteLine( c.CustomerID );
}
}
Using dbContext As New EntitiesModel()
Dim customers As IQueryable(Of Customer) = From customer In dbContext.Customers
Where customer.Country = "Germany"
Select customer
For Each c As Customer In customers
Console.WriteLine(c.CustomerID)
Next c
End Using
The following example in method-based query syntax shows a query that returns results where the customer country is equal to "Germany":
using ( EntitiesModel dbContext = new EntitiesModel() )
{
IQueryable<Customer> customers = dbContext.Customers.Where( c => c.Country == "Germany" );
foreach ( Customer c in customers )
{
Console.WriteLine( c.CustomerID );
}
}
Using dbContext As New EntitiesModel()
Dim customers As IQueryable(Of Customer) = dbContext.Customers.Where(Function(c) c.Country = "Germany")
For Each c As Customer In customers
Console.WriteLine(c.CustomerID)
Next c
End Using