@@ -14,97 +14,103 @@ public sealed class BikeTrackingDbContext(DbContextOptions<BikeTrackingDbContext
1414
1515 protected override void OnModelCreating ( ModelBuilder modelBuilder )
1616 {
17- modelBuilder . Entity < UserEntity > ( entity =>
17+ modelBuilder . Entity < UserEntity > ( static entity =>
1818 {
1919 entity . ToTable ( "Users" ) ;
20- entity . HasKey ( x => x . UserId ) ;
21- entity . Property ( x => x . DisplayName ) . IsRequired ( ) . HasMaxLength ( 120 ) ;
22- entity . Property ( x => x . NormalizedName ) . IsRequired ( ) . HasMaxLength ( 120 ) ;
23- entity . Property ( x => x . CreatedAtUtc ) . IsRequired ( ) ;
24- entity . Property ( x => x . IsActive ) . HasDefaultValue ( true ) ;
20+ entity . HasKey ( static x => x . UserId ) ;
21+ entity . Property ( static x => x . DisplayName ) . IsRequired ( ) . HasMaxLength ( 120 ) ;
22+ entity . Property ( static x => x . NormalizedName ) . IsRequired ( ) . HasMaxLength ( 120 ) ;
23+ entity . Property ( static x => x . CreatedAtUtc ) . IsRequired ( ) ;
24+ entity . Property ( static x => x . IsActive ) . HasDefaultValue ( true ) ;
2525
26- entity . HasIndex ( x => x . NormalizedName ) . IsUnique ( ) ;
26+ entity . HasIndex ( static x => x . NormalizedName ) . IsUnique ( ) ;
2727
2828 entity
29- . HasOne ( x => x . Credential )
30- . WithOne ( x => x . User )
31- . HasForeignKey < UserCredentialEntity > ( x => x . UserId )
29+ . HasOne ( static x => x . Credential )
30+ . WithOne ( static x => x . User )
31+ . HasForeignKey < UserCredentialEntity > ( static x => x . UserId )
3232 . OnDelete ( DeleteBehavior . Cascade ) ;
3333
3434 entity
35- . HasOne ( x => x . AuthAttemptState )
36- . WithOne ( x => x . User )
37- . HasForeignKey < AuthAttemptStateEntity > ( x => x . UserId )
35+ . HasOne ( static x => x . AuthAttemptState )
36+ . WithOne ( static x => x . User )
37+ . HasForeignKey < AuthAttemptStateEntity > ( static x => x . UserId )
3838 . OnDelete ( DeleteBehavior . Cascade ) ;
3939 } ) ;
4040
41- modelBuilder . Entity < UserCredentialEntity > ( entity =>
41+ modelBuilder . Entity < UserCredentialEntity > ( static entity =>
4242 {
4343 entity . ToTable ( "UserCredentials" ) ;
44- entity . HasKey ( x => x . UserCredentialId ) ;
45- entity . Property ( x => x . PinHash ) . IsRequired ( ) ;
46- entity . Property ( x => x . PinSalt ) . IsRequired ( ) ;
47- entity . Property ( x => x . HashAlgorithm ) . IsRequired ( ) . HasMaxLength ( 64 ) ;
48- entity . Property ( x => x . IterationCount ) . IsRequired ( ) ;
49- entity . Property ( x => x . CredentialVersion ) . IsRequired ( ) ;
50- entity . Property ( x => x . UpdatedAtUtc ) . IsRequired ( ) ;
44+ entity . HasKey ( static x => x . UserCredentialId ) ;
45+ entity . Property ( static x => x . PinHash ) . IsRequired ( ) ;
46+ entity . Property ( static x => x . PinSalt ) . IsRequired ( ) ;
47+ entity . Property ( static x => x . HashAlgorithm ) . IsRequired ( ) . HasMaxLength ( 64 ) ;
48+ entity . Property ( static x => x . IterationCount ) . IsRequired ( ) ;
49+ entity . Property ( static x => x . CredentialVersion ) . IsRequired ( ) ;
50+ entity . Property ( static x => x . UpdatedAtUtc ) . IsRequired ( ) ;
5151 } ) ;
5252
53- modelBuilder . Entity < AuthAttemptStateEntity > ( entity =>
53+ modelBuilder . Entity < AuthAttemptStateEntity > ( static entity =>
5454 {
5555 entity . ToTable ( "AuthAttemptStates" ) ;
56- entity . HasKey ( x => x . UserId ) ;
57- entity . Property ( x => x . ConsecutiveWrongCount ) . HasDefaultValue ( 0 ) ;
58- entity . Property ( x => x . LastWrongAttemptUtc ) ;
59- entity . Property ( x => x . DelayUntilUtc ) ;
60- entity . Property ( x => x . LastSuccessfulAuthUtc ) ;
56+ entity . HasKey ( static x => x . UserId ) ;
57+ entity . Property ( static x => x . ConsecutiveWrongCount ) . HasDefaultValue ( 0 ) ;
58+ entity . Property ( static x => x . LastWrongAttemptUtc ) ;
59+ entity . Property ( static x => x . DelayUntilUtc ) ;
60+ entity . Property ( static x => x . LastSuccessfulAuthUtc ) ;
6161 } ) ;
6262
63- modelBuilder . Entity < OutboxEventEntity > ( entity =>
63+ modelBuilder . Entity < OutboxEventEntity > ( static entity =>
6464 {
6565 entity . ToTable ( "OutboxEvents" ) ;
66- entity . HasKey ( x => x . OutboxEventId ) ;
67- entity . Property ( x => x . AggregateType ) . IsRequired ( ) . HasMaxLength ( 64 ) ;
68- entity . Property ( x => x . AggregateId ) . IsRequired ( ) ;
69- entity . Property ( x => x . EventType ) . IsRequired ( ) . HasMaxLength ( 128 ) ;
70- entity . Property ( x => x . EventPayloadJson ) . IsRequired ( ) ;
71- entity . Property ( x => x . OccurredAtUtc ) . IsRequired ( ) ;
72- entity . Property ( x => x . RetryCount ) . HasDefaultValue ( 0 ) ;
73- entity . Property ( x => x . NextAttemptUtc ) . IsRequired ( ) ;
74- entity . Property ( x => x . PublishedAtUtc ) ;
75- entity . Property ( x => x . LastError ) . HasMaxLength ( 2048 ) ;
76-
77- entity . HasIndex ( x => new { x . PublishedAtUtc , x . NextAttemptUtc } ) ;
78- entity . HasIndex ( x => new { x . AggregateType , x . AggregateId } ) ;
66+ entity . HasKey ( static x => x . OutboxEventId ) ;
67+ entity . Property ( static x => x . AggregateType ) . IsRequired ( ) . HasMaxLength ( 64 ) ;
68+ entity . Property ( static x => x . AggregateId ) . IsRequired ( ) ;
69+ entity . Property ( static x => x . EventType ) . IsRequired ( ) . HasMaxLength ( 128 ) ;
70+ entity . Property ( static x => x . EventPayloadJson ) . IsRequired ( ) ;
71+ entity . Property ( static x => x . OccurredAtUtc ) . IsRequired ( ) ;
72+ entity . Property ( static x => x . RetryCount ) . HasDefaultValue ( 0 ) ;
73+ entity . Property ( static x => x . NextAttemptUtc ) . IsRequired ( ) ;
74+ entity . Property ( static x => x . PublishedAtUtc ) ;
75+ entity . Property ( static x => x . LastError ) . HasMaxLength ( 2048 ) ;
76+
77+ entity . HasIndex ( static x => new { x . PublishedAtUtc , x . NextAttemptUtc } ) ;
78+ entity . HasIndex ( static x => new { x . AggregateType , x . AggregateId } ) ;
7979 } ) ;
8080
81- modelBuilder . Entity < RideEntity > ( entity =>
81+ modelBuilder . Entity < RideEntity > ( static entity =>
8282 {
83- entity . ToTable ( "Rides" ) ;
84- entity . HasKey ( x => x . Id ) ;
85- entity . Property ( x => x . RiderId ) . IsRequired ( ) ;
86- entity . Property ( x => x . RideDateTimeLocal ) . IsRequired ( ) ;
87- entity . Property ( x => x . Miles ) . IsRequired ( ) ;
88- entity . Property ( x => x . CreatedAtUtc ) . IsRequired ( ) ;
89-
90- // Check constraints
91- entity . HasCheckConstraint ( "CK_Rides_Miles_GreaterThanZero" , "\" Miles\" > 0" ) ;
92- entity . HasCheckConstraint (
93- "CK_Rides_RideMinutes_GreaterThanZero" ,
94- "\" RideMinutes\" IS NULL OR \" RideMinutes\" > 0"
83+ entity . ToTable (
84+ "Rides" ,
85+ static tableBuilder =>
86+ {
87+ tableBuilder . HasCheckConstraint (
88+ "CK_Rides_Miles_GreaterThanZero" ,
89+ "\" Miles\" > 0"
90+ ) ;
91+ tableBuilder . HasCheckConstraint (
92+ "CK_Rides_RideMinutes_GreaterThanZero" ,
93+ "\" RideMinutes\" IS NULL OR \" RideMinutes\" > 0"
94+ ) ;
95+ }
9596 ) ;
97+ entity . HasKey ( static x => x . Id ) ;
98+ entity . Property ( static x => x . RiderId ) . IsRequired ( ) ;
99+ entity . Property ( static x => x . RideDateTimeLocal ) . IsRequired ( ) ;
100+ entity . Property ( static x => x . Miles ) . IsRequired ( ) ;
101+ entity . Property ( static x => x . CreatedAtUtc ) . IsRequired ( ) ;
96102
97103 // Index for efficient defaults query
98104 entity
99- . HasIndex ( x => new { x . RiderId , x . CreatedAtUtc } )
105+ . HasIndex ( static x => new { x . RiderId , x . CreatedAtUtc } )
100106 . IsDescending ( false , true )
101107 . HasDatabaseName ( "IX_Rides_RiderId_CreatedAtUtc_Desc" ) ;
102108
103109 // Foreign key to Users
104110 entity
105111 . HasOne < UserEntity > ( )
106112 . WithMany ( )
107- . HasForeignKey ( x => x . RiderId )
113+ . HasForeignKey ( static x => x . RiderId )
108114 . OnDelete ( DeleteBehavior . Cascade ) ;
109115 } ) ;
110116 }
0 commit comments