diff UnitTests/Linq/UserTests/SelectManyUpdateTest.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UnitTests/Linq/UserTests/SelectManyUpdateTest.cs	Thu Mar 27 21:46:09 2014 +0400
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+using BLToolkit.Data.DataProvider;
+using BLToolkit.Data.Linq;
+using BLToolkit.DataAccess;
+using BLToolkit.Mapping;
+
+using NUnit.Framework;
+
+namespace Data.Linq.UserTests
+{
+	[TestFixture]
+	public class SelectManyUpdateTest : TestBase
+	{
+		public new class Child
+		{
+			[Identity, PrimaryKey(1)] public int  ParentID { get; set; }
+			[Nullable]                public int? ChildID { get; set; }
+
+			[AssociationAttribute(ThisKey = "ParentID", OtherKey = "ChildID", CanBeNull = true)]
+			public List<Child> Children { get; set; }
+		}
+
+		public new class Parent
+		{
+			[Identity, PrimaryKey(1)] public int  ParentID { get; set; }
+			[Nullable]                public int? Value1   { get; set; }
+
+			[AssociationAttribute(ThisKey = "ParentID", OtherKey = "Value1", CanBeNull = true)]
+			public List<Parent> Values { get; set; }
+
+			[AssociationAttribute(ThisKey = "ParentID", OtherKey = "ParentID", CanBeNull = true)]
+			public List<Child> Children { get; set; }
+		}
+
+		[Test]
+		public void Test1([DataContexts(ProviderName.Access, ProviderName.Informix, ProviderName.MySql)] string context)
+		{
+			var harnessIds = new int[2];
+
+			using (var db = GetDataContext(context))
+				db.GetTable<Parent>()
+					.Where     (x => harnessIds.Contains(x.ParentID))
+					.SelectMany(x => x.Values)
+					.Set       (x => x.Value1, (long?)null)
+					.Update();
+		}
+
+		[Test]
+		public void Test2([DataContexts(ProviderName.Access, ProviderName.Informix, ProviderName.MySql)] string context)
+		{
+			var harnessIds = new int[2];
+
+			using (var db = GetDataContext(context))
+				db.GetTable<Parent>()
+					.Where     (x => harnessIds.Contains(x.ParentID))
+					.SelectMany(x => x.Children)
+					.SelectMany(x => x.Children)
+					.Set       (x => x.ChildID, 10)
+					.Update();
+		}
+	}
+}