@@ -16,9 +16,8 @@ public class SampleContext : DbContext
1616 // 1. Throw when can not generate a query instead of loading everything into memory
1717 optionsBuilder .ThrowOnQueryClientEvaluation ();
1818
19- // 2. Add the support for DynamicDataMasking
20- optionsBuilder .ReplaceService <IMigrationsSqlGenerator , ExtendedMigrationSqlServerGenerator >();
21- optionsBuilder .ReplaceService <IMigrationsAnnotationProvider , ExtendedSqlServerMigrationsAnnotationProvider >();
19+ // 2. Use EntityFrameworkCoreExtensions (add DynamicDataMasking support)
20+ optionsBuilder .UseEntityFrameworkCoreExtensions ();
2221
2322 base .OnConfiguring (optionsBuilder );
2423 }
@@ -30,39 +29,21 @@ public class SampleContext : DbContext
3029 // 3. Set Cascade as a default delete behaviour
3130 modelBuilder .OverrideDeleteBehaviour (DeleteBehavior .Cascade );
3231
33- // 4. Add dynamic data masking (https://docs.microsoft.com/en-us/sql/relational-databases/security/dynamic-data-masking)
34- modelBuilder .Entity <Customer >()
35- .Property (t => t .Surname )
36- .HasAnnotation (AnnotationConstants .DynamicDataMasking , MaskingFunctions .Default ());
37- modelBuilder .Entity <Customer >()
38- .Property (t => t .DiscountCardNumber )
39- .HasAnnotation (AnnotationConstants .DynamicDataMasking , MaskingFunctions .Random (10 , 100 ));
40- modelBuilder .Entity <Customer >()
41- .Property (t => t .Phone )
42- .HasAnnotation (AnnotationConstants .DynamicDataMasking , MaskingFunctions .Partial (2 , " XX-XX" , 1 ));
32+ // 4. Add dynamic data masking (https://docs.microsoft.com/en-us/sql/relational-databases/security/dynamic-data-masking)
33+ modelBuilder .Entity <Customer >().Property (t => t .Surname ).HasDataMask (MaskingFunctions .Default ());
34+ modelBuilder .Entity <Customer >().Property (t => t .DiscountCardNumber ).HasDataMask (MaskingFunctions .Random (10 , 100 ));
35+ modelBuilder .Entity <Customer >().Property (t => t .Phone ).HasDataMask (MaskingFunctions .Partial (2 , " XX-XX" , 1 ));
4336 }
4437
4538 public DbSet <Customer > Customers { get ; set ; }
4639}
47-
48- public class Customer
49- {
50- public int Id { get ; set ; }
51-
52- // 5. Another way to add DynamicDataMask
53- [DataMasking (MaskingFunction = " default()" )]
54- public string Name { get ; set ; }
55- }
5640
5741static void Main (string [] args )
5842{
5943 using (var context = new SampleContext ())
6044 {
6145 // 6. Will not throw when UseInMemoryDatabase is used
62- context .Database .MigrateIfSupported ();
63-
64- // 7. Will throw instead of loading everything into memory
65- var customers = context .Customers .Where (t => SomeUnsupportedFunction (t .Phone )).ToList ();
46+ context .Database .MigrateIfSupported ();
6647 }
6748}
6849```
0 commit comments