-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathObjects.cs
297 lines (267 loc) · 7.44 KB
/
Objects.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
using System;
using System.Collections.Generic;
using System.Linq;
using Examples;
using MongoDB.Bson;
using Realms;
namespace Examples.Models
{
public partial class Address10 : IEmbeddedObject
{
public ObjectId Id { get; set; }
public string Street { get; set; }
public string City { get; set; }
}
public partial class Contact10 : IRealmObject
{
[PrimaryKey]
[MapTo("_id")]
public ObjectId Id { get; set; }
public string Name { get; set; }
public Address10? Address { get; set; } // embed a single address
}
// STAND-ALONE class; not used elsewhere
// :snippet-start: primary-key
// :replace-start: {
// "terms": {
// "Person_Required": "Person",
// "Doge": "Dog",
// "//[NotPrimaryKey]": "[PrimaryKey]" }
// }
public partial class Doge : IRealmObject
{
//:remove-start:
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; }
//:remove-end:
//[NotPrimaryKey]
public string Name { get; set; }
public int Age { get; set; }
public Person_Required? Owner { get; set; }
}
//:replace-end:
// :snippet-end:
public partial class Person_Required : IRealmObject
{
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; }
public string Name { get; set; }
public IList<Dog_OMAS> Dogs { get; }
}
// :snippet-start: default
// :replace-start: {
// "terms": {
// "PersonB": "Person",
// "Person_Required": "PhoneNumber"}
// }
public partial class PersonB : IRealmObject
{
//:remove-start:
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; }
//:remove-end:
public string Name { get; set; } = "foo";
public IList<Person_Required> PhoneNumbers { get; } = null!;
}
// :replace-end:
// :snippet-end:
// :snippet-start: index
// :replace-start: {
// "terms": {
// "Person_Index": "Person",
// "Dog_OMAS": "Dog"}
// }
public partial class Person_Index : IRealmObject
{
//:remove-start:
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; }
//:remove-end:
[Indexed(IndexType.General)]
public string Name { get; set; }
[Indexed(IndexType.FullText)]
public string Biography { get; set; }
}
// :replace-end:
// :snippet-end:
public partial class Dog_Rel_One_to_One : IRealmObject
{
//:remove-start:
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; }
//:remove-end:
// ... other property declarations
public Person_Rel_One_to_One? Owner { get; set; }
}
public partial class Person_Rel_One_to_One : IRealmObject
{
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; }
public string Name { get; set; }
}
public partial class Dog_Rel_One_to_Many : IRealmObject
{
//:remove-start:
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; }
//:remove-end:
// ... other property declarations
public string Name { get; set; }
}
public partial class Person_Rel_One_to_Many : IRealmObject
{
//:remove-start:
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; }
//:remove-end:
// ... other property declarations
public IList<Dog_Rel_One_to_Many> Dogs { get; }
}
partial class Dog_Inverse : IRealmObject
{
//:remove-start:
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; }
//:remove-end:
// To-one relationship from the Dog to its owner
public Person_Inverse? Owner { get; set; }
}
partial class Person_Inverse : IRealmObject
{
//:remove-start:
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; }
//:remove-end:
// An inverse relationship that returns all Dog instances that have Dog.Owner set to
// the current Person.
[Backlink(nameof(Dog_Inverse.Owner))]
public IQueryable<Dog_Inverse> Dogs { get; }
// To-many relationship, containing a collection of all hobbies the current person enjoys
public IList<Hobby> Hobbies { get; }
}
partial class Hobby : IRealmObject
{
//:remove-start:
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; }
//:remove-end:
// An inverse relationship that returns all Person instances that have the current Hobby
// instance in their Hobbies list.
[Backlink(nameof(Person_Inverse.Hobbies))]
public IQueryable<Person_Inverse> PeopleWithThatHobby { get; }
}
class IgnorantRenamer
{
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; }
// :snippet-start: ignore
// Rather than store an Image in Realm,
// store the path to the Image...
public string ThumbnailPath { get; set; }
// ...and the Image itself can be
// in-memory when the app is running:
[Ignored]
public Image? Thumbnail { get; set; }
// :snippet-end:
}
// :snippet-start: rename
// :replace-start: {
// "terms": {
// "PersonH": "Person"}
// }
public partial class PersonH : IRealmObject
{
//:remove-start:
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; }
//:remove-end:
[MapTo("moniker")]
public string Name { get; set; }
}
// :replace-end:
// :snippet-end:
public class Image
{
}
}
public partial class CustomGetterSetter : IRealmObject
{
[PrimaryKey]
public string _id { get; set; } = MongoDB.Bson.ObjectId.GenerateNewId().ToString();
// :snippet-start: custom-setter
// This property will be stored in the Realm
private string email { get; set; }
// Custom validation of the email property.
// This property is *not* stored in Realm.
public string Email
{
get { return email; }
set
{
if (!value.Contains("@")) throw new Exception("Invalid email address");
email = value;
}
}
// :snippet-end:
}
// :snippet-start: rename-class
// :replace-start: {
// "terms": {
// "PersonI": "Person",
// "DogB": "Dog"}
// }
[MapTo("Human")]
public partial class PersonI : IRealmObject
{
//:remove-start:
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; }
//:remove-end:
public string Name { get; set; }
}
// :replace-end:
// :snippet-end:
// :snippet-start: subset
// :replace-start: {
// "terms": {
// "Dog_OMAS": "Dog"}
// }
// Declare your schema
partial class LoneClass : IRealmObject
{
//:remove-start:
[PrimaryKey]
[MapTo("_id")]
public ObjectId ID { get; set; }
//:remove-end:
public string Name { get; set; }
}
class AnotherClass
{
private void SetUpMyRealmConfig()
{
// Define your config with a single class
var config = new RealmConfiguration("RealmWithOneClass.realm");
config.Schema = new[] { typeof(LoneClass) };
// Or, specify multiple classes to use in the Realm
config.Schema = new[] { typeof(Dog_OMAS), typeof(Cat) };
}
}
// :replace-end:
// :snippet-end:
class Cat
{ }