Working on Chap10

Chap10
jason-zhu 2023-10-22 11:46:19 +11:00
parent d9e8bf8553
commit 2fe2761d0b
7 changed files with 81 additions and 0 deletions

View File

@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/contentModel.xml
/.idea.WorkingWithEFCore.iml
/modules.xml
/projectSettingsUpdater.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="accountSettings">
<option name="activeRegion" value="us-east-1" />
<option name="recentlyUsedRegions">
<list>
<option value="us-east-1" />
</list>
</option>
</component>
</project>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="Microsoft SQL Server - @localhost" uuid="4b4ea279-159d-49a1-9d2c-0fafe90fec40">
<driver-ref>sqlserver.ms</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</jdbc-driver>
<jdbc-url>jdbc:sqlserver://localhost</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>

View File

@ -3,6 +3,7 @@ using Packt.Shared;
Console.WriteLine($"Using {ProjectConstants.DatabaseProvider} database provider."); Console.WriteLine($"Using {ProjectConstants.DatabaseProvider} database provider.");
QueryingCategories(); QueryingCategories();
FilteredIncludes();
static void QueryingCategories() static void QueryingCategories()
{ {
@ -24,3 +25,29 @@ static void QueryingCategories()
} }
} }
} }
static void FilteredIncludes()
{
using (Northwind db = new())
{
Console.Write("Enter a minimum for units in stock: ");
string unitsInStock = Console.ReadLine() ?? "10";
int stock = int.Parse(unitsInStock);
IQueryable<Category>? categories = db.Categories?
.Include(c => c.Products.Where(p => p.Stock >= stock));
if (categories is null)
{
Console.WriteLine("No categories found.");
return;
}
foreach (Category c in categories)
{
Console.WriteLine($"{c.CategoryName} has {c.Products.Count} products with a minimum of {stock} units in stock.");
foreach (Product p in c.Products)
{
Console.WriteLine($" {p.ProductName} has {p.Stock} units in stock.");
}
}
}
}