|
41 | 41 | // Display the storage size on the front-end |
42 | 42 | <p>Storage Used: @storageUsageText</p> |
43 | 43 | <p>Storage Quota: @storageQuotaText</p> |
44 | | - |
45 | 44 | } |
46 | 45 |
|
47 | 46 | <PageTitle>Example</PageTitle> |
|
169 | 168 | // // // DO NOT DO THIS! I only am allowing this for maximum flexibility but this is very dangerous. |
170 | 169 | // IMagicQuery<Person> unassignedDbQuery = await _MagicDb.QueryOverride<Person>("DbName", "SchemaName"); |
171 | 170 |
|
172 | | - |
173 | | - |
174 | | - |
175 | | - Person[] persons = new Person[] { |
176 | | - new Person { Name = "Zack", DateOfBirth = null, TestInt = 9, _Age = 45, GUIY = Guid.NewGuid(), DoNotMapTest = "I buried treasure behind my house", Access=Person.Permissions.CanRead}, |
177 | | - new Person { Name = "Luna", TestInt = 9, DateOfBirth = GetDateWithSameMonthDay(GetRandomYear()), _Age = 35, GUIY = Guid.NewGuid(), DoNotMapTest = "Jerry is my husband and I had an affair with Bob.", Access = Person.Permissions.CanRead|Person.Permissions.CanWrite}, |
178 | | - new Person { Name = "Jerry", TestInt = 9, DateOfBirth = GetDateWithSameMonthDay(GetRandomYear()), _Age = 35, GUIY = Guid.NewGuid(), DoNotMapTest = "My wife is amazing", Access = Person.Permissions.CanRead|Person.Permissions.CanWrite|Person.Permissions.CanCreate}, |
179 | | - new Person { Name = "Jamie", TestInt = 9, DateOfBirth = GetDateWithSameMonthDay(GetRandomYear()), _Age = 35, GUIY = Guid.NewGuid(), DoNotMapTest = "My wife is amazing", Access = Person.Permissions.CanRead|Person.Permissions.CanWrite|Person.Permissions.CanCreate}, |
180 | | - new Person { Name = "James", TestInt = 9, DateOfBirth = GetDateWithSameMonthDay(GetRandomYear()), _Age = 35, GUIY = Guid.NewGuid(), DoNotMapTest = "My wife is amazing", Access = Person.Permissions.CanRead|Person.Permissions.CanWrite|Person.Permissions.CanCreate}, |
181 | | - new Person { Name = "Jack", TestInt = 9, DateOfBirth = GetDateWithSameMonthDay(GetRandomYear()), _Age = 35, GUIY = Guid.NewGuid(), DoNotMapTest = "My wife is amazing", Access = Person.Permissions.CanRead|Person.Permissions.CanWrite|Person.Permissions.CanCreate}, |
182 | | - new Person { Name = "Jon", TestInt = 9, DateOfBirth = GetDateWithSameMonthDay(GetRandomYear()), _Age = 37, GUIY = Guid.NewGuid(), DoNotMapTest = "I black mail Luna for money because I know her secret", Access = Person.Permissions.CanRead}, |
183 | | - new Person { Name = "Jack", TestInt = 9, DateOfBirth = GetDateWithSameMonthDay(GetRandomYear()), _Age = 37, GUIY = Guid.NewGuid(), DoNotMapTest = "I have a drug problem", Access = Person.Permissions.CanRead|Person.Permissions.CanWrite}, |
184 | | - new Person { Name = "Cathy", TestInt = 9, DateOfBirth = GetDateWithSameMonthDay(GetRandomYear()), _Age = 22, GUIY = Guid.NewGuid(), DoNotMapTest = "I got away with reading Bobs diary.", Access = Person.Permissions.CanRead | Person.Permissions.CanWrite}, |
185 | | - new Person { Name = "Bob", TestInt = 3 , DateOfBirth = GetDateWithSameMonthDay(GetRandomYear()), _Age = 69, GUIY = Guid.NewGuid(), DoNotMapTest = "I caught Cathy reading my diary, but I'm too shy to confront her.", Access = Person.Permissions.CanRead }, |
186 | | - new Person { Name = "Alex", TestInt = 3 , DateOfBirth = null, _Age = 80, GUIY = Guid.NewGuid(), DoNotMapTest = "I'm naked! But nobody can know!" }, |
187 | | - new Person { Name = "Zapoo", DateOfBirth = null, TestInt = 9, _Age = 45, GUIY = Guid.NewGuid(), DoNotMapTest = "I buried treasure behind my house", Access=Person.Permissions.CanRead}, |
188 | | - |
189 | | - new Person { Name = "Sarah", TestInt = -1, _Age = 30, GUIY = Guid.NewGuid(), DoNotMapTest = "I hate my job", Access=Person.Permissions.CanRead}, |
190 | | - new Person { Name = "Michael", TestInt = 15, _Age = 50, GUIY = Guid.NewGuid(), DoNotMapTest = "I'm hiding a big secret", Access=Person.Permissions.CanRead | Person.Permissions.CanWrite}, |
191 | | - new Person { Name = "Tommy", TestInt = 7, _Age = 12, GUIY = Guid.NewGuid(), DoNotMapTest = "I am just a kid" }, |
192 | | - new Person { Name = "Grace", TestInt = 3, _Age = 90, GUIY = Guid.NewGuid(), DoNotMapTest = "I have seen the world" }, |
193 | | - new Person { Name = "Xylophone", TestInt = 9, _Age = 27, GUIY = Guid.NewGuid(), DoNotMapTest = "I have the weirdest name" }, |
194 | | - new Person { Name = "Yasmine", TestInt = 9, _Age = 40, GUIY = Guid.NewGuid(), DoNotMapTest = null }, |
195 | | - |
196 | | - // Additional test case persons to stress-test LINQ validation |
197 | | - new Person { Name = "Alicia", TestInt = 42, _Age = 16, GUIY = Guid.NewGuid(), DoNotMapTest = "I just got my driver's license" }, |
198 | | - new Person { Name = "Ben", TestInt = 0, _Age = 25, GUIY = Guid.NewGuid(), DoNotMapTest = "I have no TestInt value" }, |
199 | | - new Person { Name = "Clara", TestInt = 100, _Age = 65, GUIY = Guid.NewGuid(), DoNotMapTest = "I retired last week", Access = Person.Permissions.CanRead | Person.Permissions.CanWrite }, |
200 | | - new Person { Name = "Danny", TestInt = 9, _Age = 40, GUIY = Guid.NewGuid(), DoNotMapTest = null }, // Null handling |
201 | | - new Person { Name = "Elliot", TestInt = -20, _Age = 55, GUIY = Guid.NewGuid(), DoNotMapTest = "My test int is negative" }, |
202 | | - new Person { Name = "Fiona", TestInt = 11, _Age = 33, GUIY = Guid.NewGuid(), DoNotMapTest = "I like puzzles" }, |
203 | | - new Person { Name = "George", TestInt = 8, _Age = 72, GUIY = Guid.NewGuid(), DoNotMapTest = "I fought in a war", Access = Person.Permissions.CanRead | Person.Permissions.CanWrite | Person.Permissions.CanCreate }, |
204 | | - new Person { Name = "Henry", TestInt = 99, _Age = 29, GUIY = Guid.NewGuid(), DoNotMapTest = "I almost made it to 100 TestInt" }, |
205 | | - new Person { Name = "Isla", TestInt = 2, _Age = 18, GUIY = Guid.NewGuid(), DoNotMapTest = "I just turned into an adult" }, |
206 | | - new Person { Name = "Jackie", TestInt = 75, _Age = 60, GUIY = Guid.NewGuid(), DoNotMapTest = "I love cooking" }, |
207 | | - new Person { Name = "Kevin", TestInt = 5, _Age = 48, GUIY = Guid.NewGuid(), DoNotMapTest = "I own a small business" }, |
208 | | - new Person { Name = "Liam", TestInt = 9, _Age = 55, GUIY = Guid.NewGuid(), DoNotMapTest = "I just became a grandfather" }, |
209 | | - new Person { Name = "Mona", TestInt = 88, _Age = 35, GUIY = Guid.NewGuid(), DoNotMapTest = "I am a detective", Access = Person.Permissions.CanRead | Person.Permissions.CanWrite }, |
210 | | - new Person { Name = "Nathan", TestInt = 7, _Age = 27, GUIY = Guid.NewGuid(), DoNotMapTest = "I play guitar" }, |
211 | | - new Person { Name = "Olivia", TestInt = 13, _Age = 45, GUIY = Guid.NewGuid(), DoNotMapTest = "I run marathons" }, |
212 | | - new Person { Name = "Patrick", TestInt = 3, _Age = 52, GUIY = Guid.NewGuid(), DoNotMapTest = "I work in IT" }, |
213 | | - new Person { Name = "Quinn", TestInt = 22, _Age = 42, GUIY = Guid.NewGuid(), DoNotMapTest = "I design board games" }, |
214 | | - new Person { Name = "Rachel", TestInt = 77, _Age = 36, GUIY = Guid.NewGuid(), DoNotMapTest = "I am a pilot" }, |
215 | | - new Person { Name = "Steve", TestInt = 9, _Age = 38, GUIY = Guid.NewGuid(), DoNotMapTest = "I am an engineer" }, |
216 | | - new Person { Name = "Tina", TestInt = 3, _Age = 68, GUIY = Guid.NewGuid(), DoNotMapTest = "I just got my pension" }, |
217 | | - new Person { Name = "Uma", TestInt = 14, _Age = 39, GUIY = Guid.NewGuid(), DoNotMapTest = "I teach yoga" }, |
218 | | - new Person { Name = "Victor", TestInt = 6, _Age = 31, GUIY = Guid.NewGuid(), DoNotMapTest = "I am an artist" }, |
219 | | - new Person { Name = "Wendy", TestInt = 50, _Age = 50, GUIY = Guid.NewGuid(), DoNotMapTest = "My age matches my test int" }, |
220 | | - new Person { Name = "Xander", TestInt = 19, _Age = 21, GUIY = Guid.NewGuid(), DoNotMapTest = "I am a college student" }, |
221 | | - new Person { Name = "Yara", TestInt = 90, _Age = 32, GUIY = Guid.NewGuid(), DoNotMapTest = "I work in finance" }, |
222 | | - new Person { Name = "Zane", TestInt = 101, _Age = 47, DateOfBirth = new DateTime(2020, 2, 10), GUIY = Guid.NewGuid(), DoNotMapTest = "I love motorcycles" }, |
223 | | - }; |
224 | | - |
| 171 | + Person[] persons = TestBase.Data.PersonData.persons; |
225 | 172 |
|
226 | 173 | var count = 0; |
227 | 174 | foreach (var p in persons) |
|
232 | 179 | p.TestIntStable2 = 10; |
233 | 180 | } |
234 | 181 |
|
235 | | - |
236 | | - |
237 | 182 | //var storageInfo = await _MagicDb.GetStorageEstimateAsync(); |
238 | 183 | //storageQuota = storageInfo.QuotaInMegabytes; |
239 | 184 | //storageUsage = storageInfo.UsageInMegabytes; |
240 | 185 |
|
241 | | - |
242 | | - |
243 | | - |
244 | 186 | // WhereExample = await (manager.Where<Person>(x => x.Name.StartsWith("c", StringComparison.OrdinalIgnoreCase) |
245 | 187 | // || x.Name.StartsWith("l", StringComparison.OrdinalIgnoreCase) |
246 | 188 | // || x.Name.StartsWith("j", StringComparison.OrdinalIgnoreCase) && x._Age > 35 |
|
253 | 195 |
|
254 | 196 | allPeople = await personQuery.ToListAsync(); |
255 | 197 |
|
256 | | - |
257 | | - |
258 | 198 | List<Person> people = await personQuery.ToListAsync(); |
259 | 199 | StateHasChanged(); |
260 | 200 |
|
|
271 | 211 | var asdf = d.DayOfWeek; |
272 | 212 | var asdf2 = d.DayOfYear; |
273 | 213 |
|
274 | | - |
275 | 214 | // I know the validation of "allPeople" targets differently but I know this is the right result. |
276 | 215 | // This is a weird .NET memory grab weirdess. |
277 | 216 |
|
278 | | - |
279 | | - |
280 | 217 | RunTest("Date Equal", |
281 | 218 | await personQuery.Where(x => x.DateOfBirth.Value.Date == new DateTime(2020, 2, 10)).ToListAsync(), |
282 | 219 | allPeople.Where(x => x.DateOfBirth.HasValue && x.DateOfBirth.Value.Date == new DateTime(2020, 2, 10))); |
|
357 | 294 | await personQuery.Where(x => x.DateOfBirth.Value.DayOfYear <= 41).ToListAsync(), |
358 | 295 | allPeople.Where(x => x.DateOfBirth.HasValue && x.DateOfBirth.Value.DayOfYear <= 41)); |
359 | 296 |
|
360 | | - |
361 | 297 | RunTest("Date Day Of Week Equal", |
362 | 298 | await personQuery.Where(x => x.DateOfBirth.Value.DayOfWeek == DayOfWeek.Monday).ToListAsync(), |
363 | 299 | allPeople.Where(x => x.DateOfBirth.HasValue && x.DateOfBirth.Value.DayOfWeek == DayOfWeek.Monday)); |
|
422 | 358 | RunTest("Contains Test", await personQuery.Where(x => x.Name.Contains("zac", StringComparison.OrdinalIgnoreCase)).ToListAsync(), |
423 | 359 | allPeople.Where(x => x.Name.Contains("zac", StringComparison.OrdinalIgnoreCase))); |
424 | 360 |
|
425 | | - |
426 | 361 | RunTest("Not Contains Test", await personQuery.Where(x => !x.Name.Contains("zac", StringComparison.OrdinalIgnoreCase)).ToListAsync(), |
427 | 362 | allPeople.Where(x => !x.Name.Contains("zac", StringComparison.OrdinalIgnoreCase))); |
428 | 363 |
|
|
494 | 429 | */ |
495 | 430 | allPeople.OrderBy(x => x.Name).ThenBy(x => x._Id).TakeLast(2)); |
496 | 431 |
|
497 | | - |
498 | 432 | var totalPersons = await personQuery.CountAsync(); |
499 | 433 | var test1 = await personQuery.FirstOrDefaultAsync(); |
500 | 434 | var test2 = await personQuery.FirstOrDefaultAsync(x => x.Name == "Victor"); |
|
518 | 452 | RunTest("Cursor Last Or Default Where Test", new List<Person>() { await personQuery.Cursor(x => x.Name == "Victor").OrderBy(x => x._Age).LastOrDefaultAsync() }, |
519 | 453 | new List<Person>() { allPeople.Where(x => x.Name == "Victor").OrderBy(x => x._Age).ThenBy(x => x._Id).LastOrDefault() }); |
520 | 454 |
|
521 | | - |
522 | 455 | RunTest("Index First Or Default Test", new List<Person>() { await personQuery.OrderBy(x => x._Id).FirstOrDefaultAsync() }, |
523 | 456 | new List<Person>() { allPeople.OrderBy(x => x._Id).ThenBy(x => x._Id).FirstOrDefault() }); |
524 | 457 |
|
|
595 | 528 | .ToListAsync(), |
596 | 529 | allPeople.Where(x => x._Age < 60).OrderByDescending(x => x._Age).ThenByDescending(x => x._Id).TakeLast(2)); |
597 | 530 |
|
598 | | - |
599 | 531 | //await Task.Delay(10000); |
600 | 532 | // 🧩 Complex Nested Conditions |
601 | 533 | RunTest("Nested OR within AND", |
|
673 | 605 | .ToListAsync(), |
674 | 606 | allPeople.OrderByDescending(x => x._Age).ThenByDescending(x => x._Id).TakeLast(5)); |
675 | 607 |
|
676 | | - |
677 | 608 | // Return ToListAsync |
678 | 609 | RunTest("Return ToListAsync", |
679 | 610 | await personQuery.ToListAsync(), |
|
0 commit comments