mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-04-05 14:25:37 +00:00
Initial commit
This commit is contained in:
parent
01d6ccf414
commit
dd097904c2
54 changed files with 37154 additions and 0 deletions
23
vs4win/Chapter10/Ch10Ex02DataSerialization/Program.cs
Normal file
23
vs4win/Chapter10/Ch10Ex02DataSerialization/Program.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using Microsoft.EntityFrameworkCore; // Include extension method
|
||||
using Packt.Shared; // Northwind, Category, Product
|
||||
|
||||
WriteLine("Creating four files containing serialized categories and products.");
|
||||
|
||||
using (Northwind db = new())
|
||||
{
|
||||
// a query to get all categories and their related products
|
||||
IQueryable<Category>? categories = db.Categories?.Include(c => c.Products);
|
||||
|
||||
if (categories is null)
|
||||
{
|
||||
WriteLine("No categories found.");
|
||||
return;
|
||||
}
|
||||
|
||||
GenerateXmlFile(categories);
|
||||
GenerateXmlFile(categories, useAttributes: false);
|
||||
GenerateCsvFile(categories);
|
||||
GenerateJsonFile(categories);
|
||||
|
||||
WriteLine($"Current directory: {Environment.CurrentDirectory}");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue