Skip to content

Commit d5d078e

Browse files
committed
Go back to auto adding query filter
1 parent b735ac5 commit d5d078e

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

AuthPermissions.AspNetCore/MultiProjPack.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<copyright>Copyright (c) 2021 Jon P Smith</copyright>
1111
<description>Provides extra authorization and multi-tenant features to an ASP.NET Core application.</description>
1212
<releaseNotes>
13-
- This NuGet only supports NET8
13+
- This NuGet only supports NET8 and all the examples are now using NET8
1414
- All vulnerable NuGets updated
1515
- Any depreciated NuGets removed
1616
</releaseNotes>

Example3.InvoiceCode/EfCoreCode/InvoicesDbContext.cs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,32 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
4646
modelBuilder.HasDefaultSchema("invoice");
4747

4848
// You could manually set up the Query Filter, but there is an easier approach
49-
//NOTE: used manually because NET8 changes the GetEntityTypes() type, which causes issues in unit tests
50-
modelBuilder.Entity<Invoice>().HasQueryFilter(x => x.DataKey == DataKey);
51-
modelBuilder.Entity<LineItem>().HasQueryFilter(x => x.DataKey == DataKey);
52-
modelBuilder.Entity<CompanyTenant>().HasQueryFilter(x => x.DataKey == DataKey);
53-
modelBuilder.Entity<LineItem>().Property(x => x.TotalPrice).HasPrecision(9, 2);
49+
//modelBuilder.Entity<Invoice>().HasQueryFilter(x => x.DataKey == DataKey);
50+
//modelBuilder.Entity<LineItem>().HasQueryFilter(x => x.DataKey == DataKey);
51+
//modelBuilder.Entity<CompanyTenant>().HasQueryFilter(x => x.DataKey == DataKey);
52+
//modelBuilder.Entity<LineItem>().Property(x => x.TotalPrice).HasPrecision(9, 2);
5453

55-
//foreach (var entityType in modelBuilder.Model.GetEntityTypes())
56-
//{
57-
// if (typeof(IDataKeyFilterReadWrite).IsAssignableFrom(entityType.ClrType))
58-
// {
59-
// entityType.AddSingleTenantReadWriteQueryFilter(this);
60-
// }
61-
// else
62-
// {
63-
// throw new Exception(
64-
// $"You haven't added the {nameof(IDataKeyFilterReadWrite)} to the entity {entityType.ClrType.Name}");
65-
// }
54+
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
55+
{
56+
if (typeof(IDataKeyFilterReadWrite).IsAssignableFrom(entityType.ClrType))
57+
{
58+
entityType.AddSingleTenantReadWriteQueryFilter(this);
59+
}
60+
else
61+
{
62+
throw new Exception(
63+
$"You haven't added the {nameof(IDataKeyFilterReadWrite)} to the entity {entityType.ClrType.Name}");
64+
}
6665

67-
// foreach (var mutableProperty in entityType.GetProperties())
68-
// {
69-
// if (mutableProperty.ClrType == typeof(decimal))
70-
// {
71-
// mutableProperty.SetPrecision(9);
72-
// mutableProperty.SetScale(2);
73-
// }
74-
// }
75-
//}
66+
foreach (var mutableProperty in entityType.GetProperties())
67+
{
68+
if (mutableProperty.ClrType == typeof(decimal))
69+
{
70+
mutableProperty.SetPrecision(9);
71+
mutableProperty.SetScale(2);
72+
}
73+
}
74+
}
7675
}
7776

7877

Example4.ShopCode/EfCoreCode/RetailDbContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
3030
{
3131
modelBuilder.HasDefaultSchema("retail");
3232

33+
// You could manually set up the Query Filter, but there is an easier approach
3334
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
3435
{
3536
if (typeof(IDataKeyFilterReadOnly).IsAssignableFrom(entityType.ClrType))

0 commit comments

Comments
 (0)