0
|
1 using System;
|
|
2 using System.Collections.Generic;
|
|
3 using System.Linq;
|
|
4
|
|
5 using BLToolkit.Data.DataProvider;
|
|
6 using BLToolkit.Data.Linq;
|
|
7 using BLToolkit.DataAccess;
|
|
8 using BLToolkit.Mapping;
|
|
9
|
|
10 using NUnit.Framework;
|
|
11
|
|
12 namespace Data.Linq.UserTests
|
|
13 {
|
|
14 [TestFixture]
|
|
15 public class SelectManyUpdateTest : TestBase
|
|
16 {
|
|
17 public new class Child
|
|
18 {
|
|
19 [Identity, PrimaryKey(1)] public int ParentID { get; set; }
|
|
20 [Nullable] public int? ChildID { get; set; }
|
|
21
|
|
22 [AssociationAttribute(ThisKey = "ParentID", OtherKey = "ChildID", CanBeNull = true)]
|
|
23 public List<Child> Children { get; set; }
|
|
24 }
|
|
25
|
|
26 public new class Parent
|
|
27 {
|
|
28 [Identity, PrimaryKey(1)] public int ParentID { get; set; }
|
|
29 [Nullable] public int? Value1 { get; set; }
|
|
30
|
|
31 [AssociationAttribute(ThisKey = "ParentID", OtherKey = "Value1", CanBeNull = true)]
|
|
32 public List<Parent> Values { get; set; }
|
|
33
|
|
34 [AssociationAttribute(ThisKey = "ParentID", OtherKey = "ParentID", CanBeNull = true)]
|
|
35 public List<Child> Children { get; set; }
|
|
36 }
|
|
37
|
|
38 [Test]
|
|
39 public void Test1([DataContexts(ProviderName.Access, ProviderName.Informix, ProviderName.MySql)] string context)
|
|
40 {
|
|
41 var harnessIds = new int[2];
|
|
42
|
|
43 using (var db = GetDataContext(context))
|
|
44 db.GetTable<Parent>()
|
|
45 .Where (x => harnessIds.Contains(x.ParentID))
|
|
46 .SelectMany(x => x.Values)
|
|
47 .Set (x => x.Value1, (long?)null)
|
|
48 .Update();
|
|
49 }
|
|
50
|
|
51 [Test]
|
|
52 public void Test2([DataContexts(ProviderName.Access, ProviderName.Informix, ProviderName.MySql)] string context)
|
|
53 {
|
|
54 var harnessIds = new int[2];
|
|
55
|
|
56 using (var db = GetDataContext(context))
|
|
57 db.GetTable<Parent>()
|
|
58 .Where (x => harnessIds.Contains(x.ParentID))
|
|
59 .SelectMany(x => x.Children)
|
|
60 .SelectMany(x => x.Children)
|
|
61 .Set (x => x.ChildID, 10)
|
|
62 .Update();
|
|
63 }
|
|
64 }
|
|
65 }
|