@@ -12,8 +12,11 @@ public class SampleContext : DbContext
1212{
1313 protected override void OnConfiguring (DbContextOptionsBuilder optionsBuilder )
1414 {
15- optionsBuilder .ThrowOnQueryClientEvaluation (); // Throw when can not generate a query instead of loading everything into memory
16- optionsBuilder .ReplaceService <IMigrationsSqlGenerator , ExtendedMigrationSqlServerGenerator >(); // Add the support for DynamicDataMasking
15+ // 1. Throw when can not generate a query instead of loading everything into memory
16+ optionsBuilder .ThrowOnQueryClientEvaluation ();
17+
18+ // 2. Add the support for DynamicDataMasking
19+ optionsBuilder .ReplaceService <IMigrationsSqlGenerator , ExtendedMigrationSqlServerGenerator >();
1720 optionsBuilder .ReplaceService <IMigrationsAnnotationProvider , ExtendedSqlServerMigrationsAnnotationProvider >();
1821
1922 base .OnConfiguring (optionsBuilder );
@@ -23,19 +26,19 @@ public class SampleContext : DbContext
2326 {
2427 base .OnModelCreating (modelBuilder );
2528
26- // Set Cascade as a default delete behaviour
29+ // 3. Set Cascade as a default delete behaviour
2730 modelBuilder .OverrideDeleteBehaviour (DeleteBehavior .Cascade );
2831
29- // Add dynamic data masking (https://docs.microsoft.com/en-us/sql/relational-databases/security/dynamic-data-masking)
32+ // 4. Add dynamic data masking (https://docs.microsoft.com/en-us/sql/relational-databases/security/dynamic-data-masking)
3033 modelBuilder .Entity <Customer >()
31- .Property (t => t .Surname )
32- .HasAnnotation (AnnotationConstants .DynamicDataMasking , MaskingFunctions .Default ());
34+ .Property (t => t .Surname )
35+ .HasAnnotation (AnnotationConstants .DynamicDataMasking , MaskingFunctions .Default ());
3336 modelBuilder .Entity <Customer >()
34- .Property (t => t .DiscountCardNumber )
35- .HasAnnotation (AnnotationConstants .DynamicDataMasking , MaskingFunctions .Random (10 , 100 ));
37+ .Property (t => t .DiscountCardNumber )
38+ .HasAnnotation (AnnotationConstants .DynamicDataMasking , MaskingFunctions .Random (10 , 100 ));
3639 modelBuilder .Entity <Customer >()
37- .Property (t => t .Phone )
38- .HasAnnotation (AnnotationConstants .DynamicDataMasking , MaskingFunctions .Partial (2 , " XX-XX" , 1 ));
40+ .Property (t => t .Phone )
41+ .HasAnnotation (AnnotationConstants .DynamicDataMasking , MaskingFunctions .Partial (2 , " XX-XX" , 1 ));
3942 }
4043
4144 public DbSet <Customer > Customers { get ; set ; }
@@ -45,7 +48,7 @@ public class Customer
4548{
4649 public int Id { get ; set ; }
4750
48- // Another way to add DynamicDataMask
51+ // 5. Another way to add DynamicDataMask
4952 [DataMasking (MaskingFunction = " default()" )]
5053 public string Name { get ; set ; }
5154}
@@ -54,9 +57,10 @@ static void Main(string[] args)
5457{
5558 using (var context = new SampleContext ())
5659 {
57- context .Database .MigrateIfSupported (); // Will not throw when UseInMemoryDatabase is used
60+ // 6. Will not throw when UseInMemoryDatabase is used
61+ context .Database .MigrateIfSupported ();
5862
59- // Will throw instead of loading everything into memory
63+ // 7. Will throw instead of loading everything into memory
6064 var customers = context .Customers .Where (t => SomeUnsupportedFunction (t .Phone )).ToList ();
6165 }
6266}
0 commit comments