Commit 65ff2b6 1 parent 5a99700 commit 65ff2b6 Copy full SHA for 65ff2b6
File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -597,3 +597,33 @@ of relation rows. UpdateById method in example could be used for modification of
597
597
598
598
Data in database will be automatically upgraded when only InKeyValue fields are added/removed/modified in primary key
599
599
definition.
600
+
601
+ ## Computed fields
602
+
603
+ ``` C#
604
+ public class Person
605
+ {
606
+ [PrimaryKey (1 )]
607
+ public uint Id { get ; set ; }
608
+
609
+ [PrimaryKey (2 )]
610
+ public string ? Email { get ; set ; }
611
+
612
+ public string ? Name { get ; set ; }
613
+
614
+ [SecondaryKey (" LowerCasedName" , IncludePrimaryKeyOrder = 1 )]
615
+ public string LowerCasedName => Name ? .ToLowerInvariant () ?? " " ;
616
+ }
617
+
618
+ public interface IPersonTable : IRelation <Person >
619
+ {
620
+ Person FindByLowerCasedName (uint id , string lowerCasedName );
621
+ }
622
+ ```
623
+
624
+ Properties with only getter and no setter are considered computed fields.
625
+ In example above ` LowerCasedName ` is computed field.
626
+ They are not stored in database value, just in secondary indexes.
627
+ They are automatically recalculated when needed, it makes updating relation little bit slower because
628
+ old value must be deserialized into object to calculate old value of secondary index. But it is faster than storing that string twice in value.
629
+ It is not possible to use computed fields in primary key.
You can’t perform that action at this time.
0 commit comments