Skip to content

Commit

Permalink
Add W8 D1 program
Browse files Browse the repository at this point in the history
  • Loading branch information
cvpfus committed Oct 23, 2023
1 parent 4e6ccb0 commit cd78655
Show file tree
Hide file tree
Showing 9 changed files with 8,861 additions and 0 deletions.
9 changes: 9 additions & 0 deletions FormulatrixBootcamp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataContractSerialization",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataContractJsonSerialization", "W6 D2\DataContractJsonSerialization\DataContractJsonSerialization.csproj", "{C649FA5B-2D7A-448B-8148-5AFC9EA821E4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "W8 D1", "W8 D1", "{1553EE85-EB84-49FF-97EE-0E0431ABD980}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFramework", "W8 D1\EntityFramework\EntityFramework.csproj", "{D65BC369-5452-4A87-8A12-49E1ABAB7F2A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -423,11 +427,16 @@ Global
{C649FA5B-2D7A-448B-8148-5AFC9EA821E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C649FA5B-2D7A-448B-8148-5AFC9EA821E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C649FA5B-2D7A-448B-8148-5AFC9EA821E4}.Release|Any CPU.Build.0 = Release|Any CPU
{D65BC369-5452-4A87-8A12-49E1ABAB7F2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D65BC369-5452-4A87-8A12-49E1ABAB7F2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D65BC369-5452-4A87-8A12-49E1ABAB7F2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D65BC369-5452-4A87-8A12-49E1ABAB7F2A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D65BC369-5452-4A87-8A12-49E1ABAB7F2A} = {1553EE85-EB84-49FF-97EE-0E0431ABD980}
{C649FA5B-2D7A-448B-8148-5AFC9EA821E4} = {AED24BE0-064B-4FAC-9168-1A5A8386EAAE}
{EDED0B55-D1A6-4710-8656-8DCC6606A66D} = {AED24BE0-064B-4FAC-9168-1A5A8386EAAE}
{865162EF-747B-46A5-8463-625FEC5E88C8} = {AED24BE0-064B-4FAC-9168-1A5A8386EAAE}
Expand Down
23 changes: 23 additions & 0 deletions W8 D1/EntityFramework/Category.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace EntityFramework;

public class Category
{
public int CategoryId { get; set; }

[Required]
[StringLength(15)]
public string? CategoryName { get; set; }

[Column(TypeName = "ntext")]
public string? Description { get; set; }

public virtual ICollection<Product> Products { get; set; }

public Category()
{
Products = new HashSet<Product>();
}
}
16 changes: 16 additions & 0 deletions W8 D1/EntityFramework/EntityFramework.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.12">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.12" />
</ItemGroup>
</Project>
20 changes: 20 additions & 0 deletions W8 D1/EntityFramework/Northwind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore;

namespace EntityFramework;

public class Northwind : DbContext
{
public DbSet<Category> Categories { get; set; }
public DbSet<Product> Products { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
string path = Path.Combine(Environment.CurrentDirectory, "Northwind.db");
optionsBuilder.UseSqlite($"Filename={path}");
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{

}
}
Binary file added W8 D1/EntityFramework/Northwind.db
Binary file not shown.
8,722 changes: 8,722 additions & 0 deletions W8 D1/EntityFramework/Northwind4SQLite.sql

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions W8 D1/EntityFramework/Product.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace EntityFramework;

public class Product
{
public int ProductId { get; set; }

[Required]
[StringLength(40)]
public string? ProductName { get; set; }

public int SupplierId { get; set; }
public int CategoryId { get; set; }

[Column("UnitPrice", TypeName = "money")]
public decimal? UnitPrice { get; set; }

[Column("UnitsInStock")]
public short? UnitsInStock { get; set; }

[Column("UnitsOnOrder")]
public short? UnitsOnOrder { get; set; }

[Column("ReorderLevel")]
public short? ReorderLevel { get; set; }

[Required]
public bool Discontinued { get; set; }

public virtual Category Category { get; set;} = null!;
}
25 changes: 25 additions & 0 deletions W8 D1/EntityFramework/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using EntityFramework;
using Microsoft.EntityFrameworkCore;

public class Program
{
static void Main()
{
using(Northwind db = new Northwind())
{
Console.WriteLine($"Name: {db.Database}");
Console.WriteLine($"Database: {db.Database.ProviderName}");
Console.WriteLine($"Database: {db.Database.CanConnect()}");

var categories = db.Categories.Where(cat => cat.CategoryId == 1).Include(cat => cat.Products);
foreach (var cat in categories)
{
Console.WriteLine(cat.CategoryName);
foreach (var product in cat.Products)
{
Console.WriteLine(" {0}", product.ProductName);
}
}
}
}
}
13 changes: 13 additions & 0 deletions W8 D1/EntityFramework/Supplier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace EntityFramework;

public class Supplier
{
public int SupplierId { get; set; }

[Required]
[StringLength(40)]
public string? CompanyName { get; set; }
}

0 comments on commit cd78655

Please sign in to comment.