diff --git a/BackingFields/BackingFields.csproj b/BackingFields/BackingFields.csproj index 2217c04..91b464a 100644 --- a/BackingFields/BackingFields.csproj +++ b/BackingFields/BackingFields.csproj @@ -7,8 +7,4 @@ enable - - - - diff --git a/BufferingAndStreaming/BufferingAndStreaming.csproj b/BufferingAndStreaming/BufferingAndStreaming.csproj index 1d7d9cf..4b7b44c 100644 --- a/BufferingAndStreaming/BufferingAndStreaming.csproj +++ b/BufferingAndStreaming/BufferingAndStreaming.csproj @@ -8,7 +8,6 @@ - diff --git a/BulkDeletes/BulkDeletes.csproj b/BulkDeletes/BulkDeletes.csproj index a88c56e..44344c2 100644 --- a/BulkDeletes/BulkDeletes.csproj +++ b/BulkDeletes/BulkDeletes.csproj @@ -7,8 +7,4 @@ enable - - - - diff --git a/BulkUpdates/BulkUpdates.csproj b/BulkUpdates/BulkUpdates.csproj index 2217c04..9139b2f 100644 --- a/BulkUpdates/BulkUpdates.csproj +++ b/BulkUpdates/BulkUpdates.csproj @@ -6,9 +6,4 @@ enable enable - - - - - diff --git a/CompiledModels/CompiledModels.csproj b/CompiledModels/CompiledModels.csproj index c0097ab..f8951b6 100644 --- a/CompiledModels/CompiledModels.csproj +++ b/CompiledModels/CompiledModels.csproj @@ -8,7 +8,6 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/CompiledQueries/CompiledQueries.csproj b/CompiledQueries/CompiledQueries.csproj index 2217c04..9139b2f 100644 --- a/CompiledQueries/CompiledQueries.csproj +++ b/CompiledQueries/CompiledQueries.csproj @@ -6,9 +6,4 @@ enable enable - - - - - diff --git a/ComplexTypes/ComplexTypes.csproj b/ComplexTypes/ComplexTypes.csproj index 55da0f8..238dbed 100644 --- a/ComplexTypes/ComplexTypes.csproj +++ b/ComplexTypes/ComplexTypes.csproj @@ -6,9 +6,4 @@ enable enable - - - - - diff --git a/DateOnlyTimeOnly/DateOnlyTimeOnly.csproj b/DateOnlyTimeOnly/DateOnlyTimeOnly.csproj index 6efafb9..ea793c4 100644 --- a/DateOnlyTimeOnly/DateOnlyTimeOnly.csproj +++ b/DateOnlyTimeOnly/DateOnlyTimeOnly.csproj @@ -7,10 +7,6 @@ enable - - - - diff --git a/DbContextPooling/DbContextPooling.csproj b/DbContextPooling/DbContextPooling.csproj index 2217c04..9139b2f 100644 --- a/DbContextPooling/DbContextPooling.csproj +++ b/DbContextPooling/DbContextPooling.csproj @@ -6,9 +6,4 @@ enable enable - - - - - diff --git a/Directory.Build.props b/Directory.Build.props index 5c249c4..7cf5ee4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,4 +5,7 @@ + + + diff --git a/EfCoreSamples.sln b/EfCoreSamples.sln index 457f176..0412989 100644 --- a/EfCoreSamples.sln +++ b/EfCoreSamples.sln @@ -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 @@ -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 diff --git a/JsonColumns/JsonColumns.csproj b/JsonColumns/JsonColumns.csproj index 2217c04..9139b2f 100644 --- a/JsonColumns/JsonColumns.csproj +++ b/JsonColumns/JsonColumns.csproj @@ -6,9 +6,4 @@ enable enable - - - - - diff --git a/KeysetPagination/KeysetPagination.csproj b/KeysetPagination/KeysetPagination.csproj index 2217c04..9139b2f 100644 --- a/KeysetPagination/KeysetPagination.csproj +++ b/KeysetPagination/KeysetPagination.csproj @@ -6,9 +6,4 @@ enable enable - - - - - diff --git a/MigrationBundles/MigrationBundles.csproj b/MigrationBundles/MigrationBundles.csproj index c0097ab..f8951b6 100644 --- a/MigrationBundles/MigrationBundles.csproj +++ b/MigrationBundles/MigrationBundles.csproj @@ -8,7 +8,6 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/OwnedEntities/OwnedEntities.csproj b/OwnedEntities/OwnedEntities.csproj index 2217c04..9139b2f 100644 --- a/OwnedEntities/OwnedEntities.csproj +++ b/OwnedEntities/OwnedEntities.csproj @@ -6,9 +6,4 @@ enable enable - - - - - diff --git a/PrimitiveCollections/ApplicationDbContext.cs b/PrimitiveCollections/ApplicationDbContext.cs new file mode 100644 index 0000000..6deb031 --- /dev/null +++ b/PrimitiveCollections/ApplicationDbContext.cs @@ -0,0 +1,19 @@ +using Common; +using Microsoft.EntityFrameworkCore; + +namespace PrimitiveCollections; + +public class ApplicationDbContext : DbContext +{ + public DbSet Products => Set(); + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder + .UseSqlServer(DbConnectionFactory.Create("PrimitiveCollections")); + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + } +} \ No newline at end of file diff --git a/PrimitiveCollections/PrimitiveCollections.csproj b/PrimitiveCollections/PrimitiveCollections.csproj new file mode 100644 index 0000000..8aa75d3 --- /dev/null +++ b/PrimitiveCollections/PrimitiveCollections.csproj @@ -0,0 +1,9 @@ + + + + Exe + net8.0 + enable + enable + + diff --git a/PrimitiveCollections/Product.cs b/PrimitiveCollections/Product.cs new file mode 100644 index 0000000..2461010 --- /dev/null +++ b/PrimitiveCollections/Product.cs @@ -0,0 +1,27 @@ +namespace PrimitiveCollections; + +public class Product +{ + public int Id { get; private set; } + public required string Name { get; init; } + + public List 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 +} \ No newline at end of file diff --git a/PrimitiveCollections/Program.cs b/PrimitiveCollections/Program.cs new file mode 100644 index 0000000..3ef8fa6 --- /dev/null +++ b/PrimitiveCollections/Program.cs @@ -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() +{ + 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(); \ No newline at end of file diff --git a/PrimitiveCollections/readme.md b/PrimitiveCollections/readme.md new file mode 100644 index 0000000..31852ee --- /dev/null +++ b/PrimitiveCollections/readme.md @@ -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) diff --git a/QueryFilters/QueryFilters.csproj b/QueryFilters/QueryFilters.csproj index 2217c04..9139b2f 100644 --- a/QueryFilters/QueryFilters.csproj +++ b/QueryFilters/QueryFilters.csproj @@ -6,9 +6,4 @@ enable enable - - - - - diff --git a/Sequences/Sequences.csproj b/Sequences/Sequences.csproj index 2217c04..9139b2f 100644 --- a/Sequences/Sequences.csproj +++ b/Sequences/Sequences.csproj @@ -6,9 +6,4 @@ enable enable - - - - - diff --git a/ShadowProperties/ShadowProperties.csproj b/ShadowProperties/ShadowProperties.csproj index 2217c04..9139b2f 100644 --- a/ShadowProperties/ShadowProperties.csproj +++ b/ShadowProperties/ShadowProperties.csproj @@ -6,9 +6,4 @@ enable enable - - - - - diff --git a/SplitQueries/SplitQueries.csproj b/SplitQueries/SplitQueries.csproj index a88c56e..8d25502 100644 --- a/SplitQueries/SplitQueries.csproj +++ b/SplitQueries/SplitQueries.csproj @@ -6,9 +6,4 @@ enable enable - - - - - diff --git a/TablePerConcreteType/TablePerConcreateType.csproj b/TablePerConcreteType/TablePerConcreateType.csproj index 2217c04..9139b2f 100644 --- a/TablePerConcreteType/TablePerConcreateType.csproj +++ b/TablePerConcreteType/TablePerConcreateType.csproj @@ -6,9 +6,4 @@ enable enable - - - - - diff --git a/TablePerHierarchy/TablePerHierarchy.csproj b/TablePerHierarchy/TablePerHierarchy.csproj index 2217c04..91b464a 100644 --- a/TablePerHierarchy/TablePerHierarchy.csproj +++ b/TablePerHierarchy/TablePerHierarchy.csproj @@ -7,8 +7,4 @@ enable - - - - diff --git a/TablePerType/TablePerType.csproj b/TablePerType/TablePerType.csproj index 2217c04..91b464a 100644 --- a/TablePerType/TablePerType.csproj +++ b/TablePerType/TablePerType.csproj @@ -7,8 +7,4 @@ enable - - - - diff --git a/Tags/Tags.csproj b/Tags/Tags.csproj index 2217c04..91b464a 100644 --- a/Tags/Tags.csproj +++ b/Tags/Tags.csproj @@ -7,8 +7,4 @@ enable - - - - diff --git a/TemporalTables/TemporalTables.csproj b/TemporalTables/TemporalTables.csproj index 2217c04..91b464a 100644 --- a/TemporalTables/TemporalTables.csproj +++ b/TemporalTables/TemporalTables.csproj @@ -7,8 +7,4 @@ enable - - - - diff --git a/UnmappedTypes/UnmappedTypes.csproj b/UnmappedTypes/UnmappedTypes.csproj index 2217c04..91b464a 100644 --- a/UnmappedTypes/UnmappedTypes.csproj +++ b/UnmappedTypes/UnmappedTypes.csproj @@ -7,8 +7,4 @@ enable - - - - diff --git a/ValueConverters/ValueConverters.csproj b/ValueConverters/ValueConverters.csproj index 2217c04..91b464a 100644 --- a/ValueConverters/ValueConverters.csproj +++ b/ValueConverters/ValueConverters.csproj @@ -7,8 +7,4 @@ enable - - - -