From ccb2d58ea572c2a4fff383fc8a613abed5498f53 Mon Sep 17 00:00:00 2001 From: "Daniel Mackay [SSW]" <2636640+danielmackay@users.noreply.github.com> Date: Tue, 19 Dec 2023 08:04:21 +1000 Subject: [PATCH 1/5] Added common Sql Server package reference to Directory.Build.props --- BackingFields/BackingFields.csproj | 4 ---- BufferingAndStreaming/BufferingAndStreaming.csproj | 1 - BulkDeletes/BulkDeletes.csproj | 4 ---- BulkUpdates/BulkUpdates.csproj | 5 ----- CompiledModels/CompiledModels.csproj | 1 - CompiledQueries/CompiledQueries.csproj | 5 ----- ComplexTypes/ComplexTypes.csproj | 5 ----- DateOnlyTimeOnly/DateOnlyTimeOnly.csproj | 4 ---- DbContextPooling/DbContextPooling.csproj | 5 ----- Directory.Build.props | 3 +++ JsonColumns/JsonColumns.csproj | 5 ----- KeysetPagination/KeysetPagination.csproj | 5 ----- MigrationBundles/MigrationBundles.csproj | 1 - OwnedEntities/OwnedEntities.csproj | 5 ----- QueryFilters/QueryFilters.csproj | 5 ----- Sequences/Sequences.csproj | 5 ----- ShadowProperties/ShadowProperties.csproj | 5 ----- SplitQueries/SplitQueries.csproj | 5 ----- TablePerConcreteType/TablePerConcreateType.csproj | 5 ----- TablePerHierarchy/TablePerHierarchy.csproj | 4 ---- TablePerType/TablePerType.csproj | 4 ---- Tags/Tags.csproj | 4 ---- TemporalTables/TemporalTables.csproj | 4 ---- UnmappedTypes/UnmappedTypes.csproj | 4 ---- ValueConverters/ValueConverters.csproj | 4 ---- 25 files changed, 3 insertions(+), 99 deletions(-) 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/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/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 - - - - From 61d76055a682d048016e5b5d6e06c2a9ea3a21ab Mon Sep 17 00:00:00 2001 From: "Daniel Mackay [SSW]" <2636640+danielmackay@users.noreply.github.com> Date: Tue, 19 Dec 2023 08:04:43 +1000 Subject: [PATCH 2/5] Added PrimativeCollections.csproj --- EfCoreSamples.sln | 6 ++++ PrimativeCollections/ApplicationDbContext.cs | 22 ++++++++++++ .../PrimativeCollections.csproj | 9 +++++ PrimativeCollections/Product.cs | 13 +++++++ PrimativeCollections/Program.cs | 35 +++++++++++++++++++ PrimativeCollections/readme.md | 12 +++++++ 6 files changed, 97 insertions(+) create mode 100644 PrimativeCollections/ApplicationDbContext.cs create mode 100644 PrimativeCollections/PrimativeCollections.csproj create mode 100644 PrimativeCollections/Product.cs create mode 100644 PrimativeCollections/Program.cs create mode 100644 PrimativeCollections/readme.md diff --git a/EfCoreSamples.sln b/EfCoreSamples.sln index 457f176..f02c101 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}") = "PrimativeCollections", "PrimativeCollections\PrimativeCollections.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/PrimativeCollections/ApplicationDbContext.cs b/PrimativeCollections/ApplicationDbContext.cs new file mode 100644 index 0000000..ced9e17 --- /dev/null +++ b/PrimativeCollections/ApplicationDbContext.cs @@ -0,0 +1,22 @@ +using Common; +using Microsoft.EntityFrameworkCore; + +namespace PrimativeCollections; + +public class ApplicationDbContext : DbContext +{ + public DbSet Products { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder + .UseSqlServer(DbConnectionFactory.Create("QueryFilters")); + + //optionsBuilder.LogTo(Console.WriteLine, new[] { RelationalEventId.CommandExecuted }); + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().HasQueryFilter(p => !p.IsDeleted); + } +} \ No newline at end of file diff --git a/PrimativeCollections/PrimativeCollections.csproj b/PrimativeCollections/PrimativeCollections.csproj new file mode 100644 index 0000000..8aa75d3 --- /dev/null +++ b/PrimativeCollections/PrimativeCollections.csproj @@ -0,0 +1,9 @@ + + + + Exe + net8.0 + enable + enable + + diff --git a/PrimativeCollections/Product.cs b/PrimativeCollections/Product.cs new file mode 100644 index 0000000..e546ef6 --- /dev/null +++ b/PrimativeCollections/Product.cs @@ -0,0 +1,13 @@ +namespace PrimativeCollections; + +public class Product +{ + public int Id { get; set; } + public string Name { get; set; } = null!; + public bool IsDeleted { get; set; } + + public override string ToString() + { + return $"Id: {Id}, Name: {Name}, IsDeleted: {IsDeleted}"; + } +} \ No newline at end of file diff --git a/PrimativeCollections/Program.cs b/PrimativeCollections/Program.cs new file mode 100644 index 0000000..83d5cac --- /dev/null +++ b/PrimativeCollections/Program.cs @@ -0,0 +1,35 @@ +using Microsoft.EntityFrameworkCore; +using PrimativeCollections; + +Console.WriteLine("Query Filter Sample"); + +using var db = new ApplicationDbContext(); +db.Database.EnsureDeleted(); +db.Database.EnsureCreated(); + +var products = new List() +{ + new Product() { Name = "Product 1" }, + new Product() { Name = "Product 2" }, + new Product() { Name = "Product 3" }, + new Product() { Name = "Product 4" }, + new Product() { Name = "Product 5" }, + new Product() { Name = "Product 6", IsDeleted = true }, + new Product() { Name = "Product 7", IsDeleted = true }, + new Product() { Name = "Product 8", IsDeleted = true }, + new Product() { Name = "Product 9" , IsDeleted = true}, + new Product() { Name = "Product 10" , IsDeleted = true} +}; + +db.Products.AddRange(products); +db.SaveChanges(); + +var visibleProducts = db.Products.ToList(); +Console.WriteLine("Visible products"); +visibleProducts.ForEach(Console.WriteLine); + +var allProducts = db.Products.IgnoreQueryFilters().ToList(); +Console.WriteLine($"All products (including deleted)"); +allProducts.ForEach(Console.WriteLine); + +Console.ReadLine(); \ No newline at end of file diff --git a/PrimativeCollections/readme.md b/PrimativeCollections/readme.md new file mode 100644 index 0000000..fb4e145 --- /dev/null +++ b/PrimativeCollections/readme.md @@ -0,0 +1,12 @@ +# Query Filters + +Query Filters allow you to apply global filters to all queries. These can be disabled on a per-query basis if needed. + +## Use Cases + +- Soft Delete - filter out deleted entities +- Multi-tenancy - filter out entities that belong to other tenants + +## Resources + +- [EF Core Docs | Query Filters](https://learn.microsoft.com/en-us/ef/core/querying/filters) \ No newline at end of file From 615f342a6f10c7cfce90fa7fcda488f29195d494 Mon Sep 17 00:00:00 2001 From: "Daniel Mackay [SSW]" <2636640+danielmackay@users.noreply.github.com> Date: Wed, 27 Dec 2023 13:54:43 +1000 Subject: [PATCH 3/5] Renamed project --- EfCoreSamples.sln | 2 +- .../ApplicationDbContext.cs | 2 +- .../PrimitiveCollections.csproj | 0 {PrimativeCollections => PrimitiveCollections}/Product.cs | 2 +- {PrimativeCollections => PrimitiveCollections}/Program.cs | 2 +- {PrimativeCollections => PrimitiveCollections}/readme.md | 0 6 files changed, 4 insertions(+), 4 deletions(-) rename {PrimativeCollections => PrimitiveCollections}/ApplicationDbContext.cs (94%) rename PrimativeCollections/PrimativeCollections.csproj => PrimitiveCollections/PrimitiveCollections.csproj (100%) rename {PrimativeCollections => PrimitiveCollections}/Product.cs (88%) rename {PrimativeCollections => PrimitiveCollections}/Program.cs (97%) rename {PrimativeCollections => PrimitiveCollections}/readme.md (100%) diff --git a/EfCoreSamples.sln b/EfCoreSamples.sln index f02c101..0412989 100644 --- a/EfCoreSamples.sln +++ b/EfCoreSamples.sln @@ -58,7 +58,7 @@ 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}") = "PrimativeCollections", "PrimativeCollections\PrimativeCollections.csproj", "{DA6D66DA-8CBB-43F8-8A95-EEB150CF3A9A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrimitiveCollections", "PrimitiveCollections\PrimitiveCollections.csproj", "{DA6D66DA-8CBB-43F8-8A95-EEB150CF3A9A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/PrimativeCollections/ApplicationDbContext.cs b/PrimitiveCollections/ApplicationDbContext.cs similarity index 94% rename from PrimativeCollections/ApplicationDbContext.cs rename to PrimitiveCollections/ApplicationDbContext.cs index ced9e17..8e2ae8c 100644 --- a/PrimativeCollections/ApplicationDbContext.cs +++ b/PrimitiveCollections/ApplicationDbContext.cs @@ -1,7 +1,7 @@ using Common; using Microsoft.EntityFrameworkCore; -namespace PrimativeCollections; +namespace PrimitiveCollections; public class ApplicationDbContext : DbContext { diff --git a/PrimativeCollections/PrimativeCollections.csproj b/PrimitiveCollections/PrimitiveCollections.csproj similarity index 100% rename from PrimativeCollections/PrimativeCollections.csproj rename to PrimitiveCollections/PrimitiveCollections.csproj diff --git a/PrimativeCollections/Product.cs b/PrimitiveCollections/Product.cs similarity index 88% rename from PrimativeCollections/Product.cs rename to PrimitiveCollections/Product.cs index e546ef6..a3f508a 100644 --- a/PrimativeCollections/Product.cs +++ b/PrimitiveCollections/Product.cs @@ -1,4 +1,4 @@ -namespace PrimativeCollections; +namespace PrimitiveCollections; public class Product { diff --git a/PrimativeCollections/Program.cs b/PrimitiveCollections/Program.cs similarity index 97% rename from PrimativeCollections/Program.cs rename to PrimitiveCollections/Program.cs index 83d5cac..7ad3804 100644 --- a/PrimativeCollections/Program.cs +++ b/PrimitiveCollections/Program.cs @@ -1,5 +1,5 @@ using Microsoft.EntityFrameworkCore; -using PrimativeCollections; +using PrimitiveCollections; Console.WriteLine("Query Filter Sample"); diff --git a/PrimativeCollections/readme.md b/PrimitiveCollections/readme.md similarity index 100% rename from PrimativeCollections/readme.md rename to PrimitiveCollections/readme.md From 4ec118ba9608e4629a5c32fa90464bd49ca543e7 Mon Sep 17 00:00:00 2001 From: "Daniel Mackay [SSW]" <2636640+danielmackay@users.noreply.github.com> Date: Wed, 27 Dec 2023 14:09:21 +1000 Subject: [PATCH 4/5] Implemented primitive collections --- PrimitiveCollections/ApplicationDbContext.cs | 7 ++---- PrimitiveCollections/Product.cs | 22 ++++++++++++++--- PrimitiveCollections/Program.cs | 26 ++++++-------------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/PrimitiveCollections/ApplicationDbContext.cs b/PrimitiveCollections/ApplicationDbContext.cs index 8e2ae8c..6deb031 100644 --- a/PrimitiveCollections/ApplicationDbContext.cs +++ b/PrimitiveCollections/ApplicationDbContext.cs @@ -5,18 +5,15 @@ namespace PrimitiveCollections; public class ApplicationDbContext : DbContext { - public DbSet Products { get; set; } + public DbSet Products => Set(); protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder - .UseSqlServer(DbConnectionFactory.Create("QueryFilters")); - - //optionsBuilder.LogTo(Console.WriteLine, new[] { RelationalEventId.CommandExecuted }); + .UseSqlServer(DbConnectionFactory.Create("PrimitiveCollections")); } protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity().HasQueryFilter(p => !p.IsDeleted); } } \ No newline at end of file diff --git a/PrimitiveCollections/Product.cs b/PrimitiveCollections/Product.cs index a3f508a..2461010 100644 --- a/PrimitiveCollections/Product.cs +++ b/PrimitiveCollections/Product.cs @@ -2,12 +2,26 @@ public class Product { - public int Id { get; set; } - public string Name { get; set; } = null!; - public bool IsDeleted { get; set; } + 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}, IsDeleted: {IsDeleted}"; + 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 index 7ad3804..3ef8fa6 100644 --- a/PrimitiveCollections/Program.cs +++ b/PrimitiveCollections/Program.cs @@ -1,7 +1,6 @@ -using Microsoft.EntityFrameworkCore; -using PrimitiveCollections; +using PrimitiveCollections; -Console.WriteLine("Query Filter Sample"); +Console.WriteLine("Primitive Collections Sample"); using var db = new ApplicationDbContext(); db.Database.EnsureDeleted(); @@ -9,27 +8,16 @@ var products = new List() { - new Product() { Name = "Product 1" }, - new Product() { Name = "Product 2" }, - new Product() { Name = "Product 3" }, - new Product() { Name = "Product 4" }, - new Product() { Name = "Product 5" }, - new Product() { Name = "Product 6", IsDeleted = true }, - new Product() { Name = "Product 7", IsDeleted = true }, - new Product() { Name = "Product 8", IsDeleted = true }, - new Product() { Name = "Product 9" , IsDeleted = true}, - new Product() { Name = "Product 10" , IsDeleted = true} + 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 visibleProducts = db.Products.ToList(); -Console.WriteLine("Visible products"); -visibleProducts.ForEach(Console.WriteLine); - -var allProducts = db.Products.IgnoreQueryFilters().ToList(); -Console.WriteLine($"All products (including deleted)"); +var allProducts = db.Products.ToList(); +Console.WriteLine("All Products"); allProducts.ForEach(Console.WriteLine); Console.ReadLine(); \ No newline at end of file From 27e4933b874e2e2d8b8f4e1bbe4e0415b1ac05d7 Mon Sep 17 00:00:00 2001 From: "Daniel Mackay [SSW]" <2636640+danielmackay@users.noreply.github.com> Date: Wed, 27 Dec 2023 14:14:47 +1000 Subject: [PATCH 5/5] Updated readme --- PrimitiveCollections/readme.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/PrimitiveCollections/readme.md b/PrimitiveCollections/readme.md index fb4e145..31852ee 100644 --- a/PrimitiveCollections/readme.md +++ b/PrimitiveCollections/readme.md @@ -1,12 +1,11 @@ -# Query Filters +# Primitive Collections -Query Filters allow you to apply global filters to all queries. These can be disabled on a per-query basis if needed. +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 -- Soft Delete - filter out deleted entities -- Multi-tenancy - filter out entities that belong to other tenants +- Keep DB Schema clean without having to create unneeded tables for primitive collections ## Resources -- [EF Core Docs | Query Filters](https://learn.microsoft.com/en-us/ef/core/querying/filters) \ No newline at end of file +- [EF Core Docs | Primitive Collections](https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-8.0/whatsnew#primitive-collections)