comparison UnitTests/Linq/UserTests/FirstOrDefaultNullReferenceExceptionTest.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using BLToolkit.DataAccess;
5 using BLToolkit.Mapping;
6
7 using NUnit.Framework;
8
9 namespace Data.Linq.UserTests
10 {
11 [TestFixture]
12 public class FirstOrDefaultNullReferenceExceptionTest : TestBase
13 {
14 [TableName("GrandChild")]
15 class Table1
16 {
17 public int ChildID;
18 }
19
20 [TableName("Child")]
21 class Table2
22 {
23 public int ChildID;
24 public int ParentID;
25
26 [Association(ThisKey = "ChildID", OtherKey = "ChildID", CanBeNull = true)]
27 public List<Table1> GrandChildren { get; set; }
28 }
29
30 [TableName("Parent")]
31 class Table3
32 {
33 public int ParentID { get; set; }
34
35 [Association(ThisKey = "ParentID", OtherKey = "ParentID", CanBeNull = true)]
36 public List<Table2> Children { get; set; }
37 }
38
39 [Test]
40 public void Test()
41 {
42 using (var db = new TestDbManager())
43 {
44 /*
45 var query =
46 from t3 in db.Parent
47 //let t1 = t3.Children.SelectMany(x => x.GrandChildren)
48 //let t2 = t3.Table2s.SelectMany(x => x.Table1s)
49 select new
50 {
51 //c2 = t1.Count(),
52 c1 = t3.Children.SelectMany(x => x.GrandChildren),
53 };
54 */
55
56 var query =
57 from t3 in db.GetTable<Table3>()
58 let t1 = t3.Children.SelectMany(x => x.GrandChildren)
59 //let t2 = t3.Table2s.SelectMany(x => x.Table1s)
60 select new
61 {
62 c2 = t1.Count(),
63 c1 = t3.Children.SelectMany(x => x.GrandChildren).Count(),
64 };
65
66 query.FirstOrDefault(p => p.c1 > 10);
67 }
68 }
69 }
70 }