How to: Execute a Parameterized Query
This topic shows how to execute a LINQ query with parameters by using OpenAccessContext. The example passes one parameter, executes the query, and iterates through the collection of Customer items.
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())
{
IQueryable<Customer> customersQuery = from customer in dbContext.Customers
where customer.Country == "Germany"
select customer;
Console.WriteLine("Customer IDs: ");
foreach (var item in customersQuery)
{
Console.WriteLine(item.CustomerID);
}
}
Using dbContext As New FluentModel()
Dim customersQuery As IQueryable(Of Customer) = From customer In dbContext.Customers
Where customer.Country = "Germany"
Select customer
Console.WriteLine("Customer IDs: ")
For Each item In customersQuery
Console.WriteLine(item.CustomerID)
Next item
End Using