Comparison Expression

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 ( FluentModel dbContext = new FluentModel() )
{
   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 FluentModel()
 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 ( FluentModel  dbContext = new FluentModel() )
{
   IQueryable<Customer> customers = dbContext.Customers.Where( c => c.Country == "Germany" );
   foreach ( Customer c in customers )
   {
       Console.WriteLine( c.CustomerID );
   }
}
Using dbContext As New FluentModel()
 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

See Also