mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-04-08 07:43:51 +00:00
Initial commit
This commit is contained in:
parent
dd097904c2
commit
2b1f5c1254
48 changed files with 36395 additions and 0 deletions
28
vscode/Chapter11/Ch11Ex02LinqQueries/Program.cs
Normal file
28
vscode/Chapter11/Ch11Ex02LinqQueries/Program.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using Packt.Shared; // Northwind, Customer
|
||||
|
||||
using (Northwind db = new())
|
||||
{
|
||||
IQueryable<string?> distinctCities =
|
||||
db.Customers.Select(c => c.City).Distinct();
|
||||
|
||||
WriteLine("A list of cities that at least one customer resides in:");
|
||||
WriteLine($"{string.Join(", ", distinctCities)}");
|
||||
WriteLine();
|
||||
|
||||
Write("Enter the name of a city: ");
|
||||
string city = ReadLine()!;
|
||||
|
||||
IQueryable<Customer> customersInCity = db.Customers.Where(c => c.City == city);
|
||||
|
||||
if (customersInCity is null)
|
||||
{
|
||||
WriteLine($"No customers found in {city}.");
|
||||
return;
|
||||
}
|
||||
|
||||
WriteLine($"There are {customersInCity.Count()} customers in {city}:");
|
||||
foreach (Customer c in customersInCity)
|
||||
{
|
||||
WriteLine($" {c.CompanyName}");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue