Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ 66 primative collections #74

Merged
merged 5 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions BackingFields/BackingFields.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion BufferingAndStreaming/BufferingAndStreaming.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
Expand Down
4 changes: 0 additions & 4 deletions BulkDeletes/BulkDeletes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
5 changes: 0 additions & 5 deletions BulkUpdates/BulkUpdates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion CompiledModels/CompiledModels.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
5 changes: 0 additions & 5 deletions CompiledQueries/CompiledQueries.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
5 changes: 0 additions & 5 deletions ComplexTypes/ComplexTypes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0"/>
</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions DateOnlyTimeOnly/DateOnlyTimeOnly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>
Expand Down
5 changes: 0 additions & 5 deletions DbContextPooling/DbContextPooling.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
<ItemGroup Condition="'$(MSBuildProjectName)' != 'Common'">
<ProjectReference Include="../Common/Common.csproj"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions EfCoreSamples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComplexTypes", "ComplexTypes\ComplexTypes.csproj", "{EC4684EA-2AA5-4AE3-B944-2740288DF141}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrimitiveCollections", "PrimitiveCollections\PrimitiveCollections.csproj", "{DA6D66DA-8CBB-43F8-8A95-EEB150CF3A9A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -164,6 +166,10 @@ Global
{EC4684EA-2AA5-4AE3-B944-2740288DF141}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC4684EA-2AA5-4AE3-B944-2740288DF141}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC4684EA-2AA5-4AE3-B944-2740288DF141}.Release|Any CPU.Build.0 = Release|Any CPU
{DA6D66DA-8CBB-43F8-8A95-EEB150CF3A9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA6D66DA-8CBB-43F8-8A95-EEB150CF3A9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA6D66DA-8CBB-43F8-8A95-EEB150CF3A9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA6D66DA-8CBB-43F8-8A95-EEB150CF3A9A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 0 additions & 5 deletions JsonColumns/JsonColumns.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
5 changes: 0 additions & 5 deletions KeysetPagination/KeysetPagination.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion MigrationBundles/MigrationBundles.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
5 changes: 0 additions & 5 deletions OwnedEntities/OwnedEntities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions PrimitiveCollections/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Common;
using Microsoft.EntityFrameworkCore;

namespace PrimitiveCollections;

public class ApplicationDbContext : DbContext
{
public DbSet<Product> Products => Set<Product>();

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlServer(DbConnectionFactory.Create("PrimitiveCollections"));
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}
}
9 changes: 9 additions & 0 deletions PrimitiveCollections/PrimitiveCollections.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
27 changes: 27 additions & 0 deletions PrimitiveCollections/Product.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace PrimitiveCollections;

public class Product
{
public int Id { get; private set; }
public required string Name { get; init; }

public List<Color> Colors { get; init; } = [];

public override string ToString()
{
return $"Id: {Id}, Name: {Name}, Colors: {string.Join(", ", Colors)}";
}
}

public enum Color
{
Red = 1,
Green,
Blue,
Yellow,
Orange,
Purple,
Black,
White,
Brown
}
23 changes: 23 additions & 0 deletions PrimitiveCollections/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using PrimitiveCollections;

Console.WriteLine("Primitive Collections Sample");

using var db = new ApplicationDbContext();
db.Database.EnsureDeleted();
db.Database.EnsureCreated();

var products = new List<Product>()
{
new() { Name = "Product 1", Colors = [Color.Black, Color.White, Color.Red]},
new() { Name = "Product 2", Colors = [Color.Blue, Color.Brown, Color.Green]},
new() { Name = "Product 3", Colors = [Color.Orange, Color.Purple, Color.Yellow]},
};

db.Products.AddRange(products);
db.SaveChanges();

var allProducts = db.Products.ToList();
Console.WriteLine("All Products");
allProducts.ForEach(Console.WriteLine);

Console.ReadLine();
11 changes: 11 additions & 0 deletions PrimitiveCollections/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Primitive Collections

Primitive Collections allow us to store a list of primitive values in a column WITHOUT having to create a separate table. EF Core will automatically do this for any primitive collections on our entities. This doesn't require any special configuration.

## Use Cases

- Keep DB Schema clean without having to create unneeded tables for primitive collections

## Resources

- [EF Core Docs | Primitive Collections](https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-8.0/whatsnew#primitive-collections)
5 changes: 0 additions & 5 deletions QueryFilters/QueryFilters.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
5 changes: 0 additions & 5 deletions Sequences/Sequences.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
5 changes: 0 additions & 5 deletions ShadowProperties/ShadowProperties.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
5 changes: 0 additions & 5 deletions SplitQueries/SplitQueries.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
5 changes: 0 additions & 5 deletions TablePerConcreteType/TablePerConcreateType.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions TablePerHierarchy/TablePerHierarchy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions TablePerType/TablePerType.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions Tags/Tags.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions TemporalTables/TemporalTables.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions UnmappedTypes/UnmappedTypes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions ValueConverters/ValueConverters.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>