You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 10, 2020. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+11-4Lines changed: 11 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -132,7 +132,13 @@ StateHasChanged();
132
132
```
133
133
### One to Many, Many to Many Association
134
134
135
-
Define a Many association by adding a property of type `List<>` to the association. For example in `Person.cs`:
135
+
Define a "One" association by adding a property of the other model. For example in `Person.cs`:
136
+
137
+
```
138
+
public Address HomeAddress { get; set; }
139
+
```
140
+
141
+
Define a "Many" association by adding a property of type `List<>` to the association. For example in `Person.cs`:
136
142
137
143
```
138
144
public List<Address> OtherAddresses { get; set; }
@@ -142,19 +148,20 @@ This is association is then used in `Associations.cshtml` like so:
142
148
143
149
```
144
150
var person = new Person { FirstName = "Many", LastName = "Test" };
151
+
person.HomeAddress = new Address { Street = "221 Baker Streeet", City = "This should be a refrence to address since Address exists in the context" };
145
152
var address1 = new Address { Street = "Many test 1", City = "Saved as a reference" };
146
153
var address2 = new Address { Street = "Many test 2", City = "Saved as a reference" };
147
154
person.OtherAddresses = new List<Address> { address1, address2 };
148
155
Context.People.Add(person);
149
-
Context.Addresses.Add(address1);
150
-
Context.Addresses.Add(address2);
151
156
Context.SaveChanges();
152
157
StateHasChanged();
153
158
```
154
159
155
160
### Maintaining Associations
156
161
157
-
Currently, associations are not maintained automatically. As in the example above, Person and Address need both be added to the context. In the future, BlazorDB may maintain those automatically.
162
+
As you can see in the example above BlazorDB will detect associations added to the model so no need to add them to the Context explicitly. In the example above, the address objects do not need to be explicitly added to the context, instead they are persisted when the person object is added and `SaveChanges()` is called.
163
+
164
+
**Note:** At this time removing/deleting is not done automatically and needs to be done manually. A future update of BlazorDB will handle deletions properly.
Copy file name to clipboardExpand all lines: docs/storageFormat.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,7 @@ Many associations are stored as an array of ids:
45
45
Contents:
46
46
47
47
* Guids - List of persisted guids
48
+
* MaxId - The last id of the StorageSet
48
49
49
50
Initial implementation will regenerate the guid on every `SaveChanges()` and the list in the metadata table. Future implementation might store metadata about the model in the model value itself, so the guid will be loaded into memory and won't be regenerated.
0 commit comments