PageRenderTime 220ms CodeModel.GetById 88ms RepoModel.GetById 1ms app.codeStats 0ms

/UnitTests/Linq/UpdateTest.cs

http://github.com/igor-tkachev/bltoolkit
C# | 749 lines | 618 code | 127 blank | 4 comment | 99 complexity | fb8a4273261379b385a9688dff03f111 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using BLToolkit.Data;
  6. using BLToolkit.Data.DataProvider;
  7. using BLToolkit.Data.Linq;
  8. using BLToolkit.DataAccess;
  9. using BLToolkit.Mapping;
  10. using BLToolkit.Mapping.MemberMappers;
  11. using NUnit.Framework;
  12. using Data.Linq;
  13. using Data.Linq.Model;
  14. #region ReSharper disable
  15. // ReSharper disable ConvertToConstant.Local
  16. #endregion
  17. namespace Update
  18. {
  19. [TestFixture]
  20. public class UpdateTest : TestBase
  21. {
  22. [Test]
  23. public void Update1()
  24. {
  25. ForEachProvider(db =>
  26. {
  27. try
  28. {
  29. var parent = new Parent1 { ParentID = 1001, Value1 = 1001 };
  30. db.Parent.Delete(p => p.ParentID > 1000);
  31. db.Insert(parent);
  32. Assert.AreEqual(1, db.Parent.Count (p => p.ParentID == parent.ParentID));
  33. Assert.AreEqual(1, db.Parent.Update(p => p.ParentID == parent.ParentID, p => new Parent { ParentID = p.ParentID + 1 }));
  34. Assert.AreEqual(1, db.Parent.Count (p => p.ParentID == parent.ParentID + 1));
  35. }
  36. finally
  37. {
  38. db.Child.Delete(c => c.ChildID > 1000);
  39. db.Parent.Delete(p => p.ParentID > 1000);
  40. }
  41. });
  42. }
  43. [Test]
  44. public void Update2()
  45. {
  46. ForEachProvider(db =>
  47. {
  48. try
  49. {
  50. var parent = new Parent1 { ParentID = 1001, Value1 = 1001 };
  51. db.Parent.Delete(p => p.ParentID > 1000);
  52. db.Insert(parent);
  53. Assert.AreEqual(1, db.Parent.Count(p => p.ParentID == parent.ParentID));
  54. Assert.AreEqual(1, db.Parent.Where(p => p.ParentID == parent.ParentID).Update(p => new Parent { ParentID = p.ParentID + 1 }));
  55. Assert.AreEqual(1, db.Parent.Count(p => p.ParentID == parent.ParentID + 1));
  56. }
  57. finally
  58. {
  59. db.Child.Delete(c => c.ChildID > 1000);
  60. db.Parent.Delete(p => p.ParentID > 1000);
  61. }
  62. });
  63. }
  64. [Test]
  65. public void Update3()
  66. {
  67. ForEachProvider(new[] { ProviderName.Informix }, db =>
  68. {
  69. try
  70. {
  71. var id = 1001;
  72. db.Child.Delete(c => c.ChildID > 1000);
  73. db.Child.Insert(() => new Child { ParentID = 1, ChildID = id});
  74. Assert.AreEqual(1, db.Child.Count(c => c.ChildID == id));
  75. Assert.AreEqual(1, db.Child.Where(c => c.ChildID == id && c.Parent.Value1 == 1).Update(c => new Child { ChildID = c.ChildID + 1 }));
  76. Assert.AreEqual(1, db.Child.Count(c => c.ChildID == id + 1));
  77. }
  78. finally
  79. {
  80. db.Child.Delete(c => c.ChildID > 1000);
  81. }
  82. });
  83. }
  84. [Test]
  85. public void Update4()
  86. {
  87. ForEachProvider(new[] { ProviderName.Informix }, db =>
  88. {
  89. try
  90. {
  91. var id = 1001;
  92. db.Child.Delete(c => c.ChildID > 1000);
  93. db.Child.Insert(() => new Child { ParentID = 1, ChildID = id});
  94. Assert.AreEqual(1, db.Child.Count(c => c.ChildID == id));
  95. Assert.AreEqual(1,
  96. db.Child
  97. .Where(c => c.ChildID == id && c.Parent.Value1 == 1)
  98. .Set(c => c.ChildID, c => c.ChildID + 1)
  99. .Update());
  100. Assert.AreEqual(1, db.Child.Count(c => c.ChildID == id + 1));
  101. }
  102. finally
  103. {
  104. db.Child.Delete(c => c.ChildID > 1000);
  105. }
  106. });
  107. }
  108. [Test]
  109. public void Update5()
  110. {
  111. ForEachProvider(new[] { ProviderName.Informix }, db =>
  112. {
  113. try
  114. {
  115. var id = 1001;
  116. db.Child.Delete(c => c.ChildID > 1000);
  117. db.Child.Insert(() => new Child { ParentID = 1, ChildID = id});
  118. Assert.AreEqual(1, db.Child.Count(c => c.ChildID == id));
  119. Assert.AreEqual(1,
  120. db.Child
  121. .Where(c => c.ChildID == id && c.Parent.Value1 == 1)
  122. .Set(c => c.ChildID, () => id + 1)
  123. .Update());
  124. Assert.AreEqual(1, db.Child.Count(c => c.ChildID == id + 1));
  125. }
  126. finally
  127. {
  128. db.Child.Delete(c => c.ChildID > 1000);
  129. }
  130. });
  131. }
  132. [Test]
  133. public void Update6()
  134. {
  135. ForEachProvider(new[] { ProviderName.Informix }, db =>
  136. {
  137. try
  138. {
  139. var id = 1001;
  140. db.Parent4.Delete(p => p.ParentID > 1000);
  141. db.Insert(new Parent4 { ParentID = id, Value1 = TypeValue.Value1 });
  142. Assert.AreEqual(1, db.Parent4.Count(p => p.ParentID == id && p.Value1 == TypeValue.Value1));
  143. Assert.AreEqual(1,
  144. db.Parent4
  145. .Where(p => p.ParentID == id)
  146. .Set(p => p.Value1, () => TypeValue.Value2)
  147. .Update());
  148. Assert.AreEqual(1, db.Parent4.Count(p => p.ParentID == id && p.Value1 == TypeValue.Value2));
  149. }
  150. finally
  151. {
  152. db.Parent4.Delete(p => p.ParentID > 1000);
  153. }
  154. });
  155. }
  156. [Test]
  157. public void Update7()
  158. {
  159. ForEachProvider(new[] { ProviderName.Informix }, db =>
  160. {
  161. try
  162. {
  163. var id = 1001;
  164. db.Parent4.Delete(p => p.ParentID > 1000);
  165. db.Insert(new Parent4 { ParentID = id, Value1 = TypeValue.Value1 });
  166. Assert.AreEqual(1, db.Parent4.Count(p => p.ParentID == id && p.Value1 == TypeValue.Value1));
  167. Assert.AreEqual(1,
  168. db.Parent4
  169. .Where(p => p.ParentID == id)
  170. .Set(p => p.Value1, TypeValue.Value2)
  171. .Update());
  172. Assert.AreEqual(1, db.Parent4.Count(p => p.ParentID == id && p.Value1 == TypeValue.Value2));
  173. Assert.AreEqual(1,
  174. db.Parent4
  175. .Where(p => p.ParentID == id)
  176. .Set(p => p.Value1, TypeValue.Value3)
  177. .Update());
  178. Assert.AreEqual(1, db.Parent4.Count(p => p.ParentID == id && p.Value1 == TypeValue.Value3));
  179. }
  180. finally
  181. {
  182. db.Parent4.Delete(p => p.ParentID > 1000);
  183. }
  184. });
  185. }
  186. [Test]
  187. public void Update8()
  188. {
  189. ForEachProvider(db =>
  190. {
  191. try
  192. {
  193. var parent = new Parent1 { ParentID = 1001, Value1 = 1001 };
  194. db.Parent.Delete(p => p.ParentID > 1000);
  195. db.Insert(parent);
  196. parent.Value1++;
  197. db.Update(parent);
  198. Assert.AreEqual(1002, db.Parent.Single(p => p.ParentID == parent.ParentID).Value1);
  199. }
  200. finally
  201. {
  202. db.Child .Delete(c => c.ChildID > 1000);
  203. db.Parent.Delete(p => p.ParentID > 1000);
  204. }
  205. });
  206. }
  207. [Test]
  208. public void Update9()
  209. {
  210. ForEachProvider(new[] { ProviderName.Informix, ProviderName.SqlCe, ProviderName.DB2, ProviderName.Firebird, "Oracle", "DevartOracle", ProviderName.OracleManaged, ProviderName.PostgreSQL, ProviderName.MySql, ProviderName.SQLite, ProviderName.Access }, db =>
  211. {
  212. try
  213. {
  214. var id = 1001;
  215. db.Child.Delete(c => c.ChildID > 1000);
  216. db.Child.Insert(() => new Child { ParentID = 1, ChildID = id});
  217. var q =
  218. from c in db.Child
  219. join p in db.Parent on c.ParentID equals p.ParentID
  220. where c.ChildID == id && c.Parent.Value1 == 1
  221. select new { c, p };
  222. Assert.AreEqual(1, db.Child.Count(c => c.ChildID == id));
  223. Assert.AreEqual(1, q.Update(db.Child, _ => new Child { ChildID = _.c.ChildID + 1, ParentID = _.p.ParentID }));
  224. Assert.AreEqual(1, db.Child.Count(c => c.ChildID == id + 1));
  225. }
  226. finally
  227. {
  228. db.Child.Delete(c => c.ChildID > 1000);
  229. }
  230. });
  231. }
  232. [Test]
  233. public void Update10()
  234. {
  235. ForEachProvider(new[] { ProviderName.Informix, ProviderName.SqlCe, ProviderName.DB2, ProviderName.Firebird, "Oracle", "DevartOracle", ProviderName.OracleManaged, ProviderName.PostgreSQL, ProviderName.MySql, ProviderName.SQLite, ProviderName.Access }, db =>
  236. {
  237. try
  238. {
  239. var id = 1001;
  240. db.Child.Delete(c => c.ChildID > 1000);
  241. db.Child.Insert(() => new Child { ParentID = 1, ChildID = id});
  242. var q =
  243. from p in db.Parent
  244. join c in db.Child on p.ParentID equals c.ParentID
  245. where c.ChildID == id && c.Parent.Value1 == 1
  246. select new { c, p };
  247. Assert.AreEqual(1, db.Child.Count(c => c.ChildID == id));
  248. Assert.AreEqual(1, q.Update(db.Child, _ => new Child { ChildID = _.c.ChildID + 1, ParentID = _.p.ParentID }));
  249. Assert.AreEqual(1, db.Child.Count(c => c.ChildID == id + 1));
  250. }
  251. finally
  252. {
  253. db.Child.Delete(c => c.ChildID > 1000);
  254. }
  255. });
  256. }
  257. //[Test]
  258. public void Update11()
  259. {
  260. ForEachProvider(db =>
  261. {
  262. var q = db.GetTable<LinqDataTypes2>().Union(db.GetTable<LinqDataTypes2>());
  263. //db.GetTable<LinqDataTypes2>().Update(_ => q.Contains(_), _ => new LinqDataTypes2 { GuidValue = _.GuidValue });
  264. q.Update(_ => new LinqDataTypes2 { GuidValue = _.GuidValue });
  265. });
  266. }
  267. [Test]
  268. public void Update12()
  269. {
  270. ForEachProvider(db =>
  271. {
  272. var parent3 = db.GetTable<Parent3>();
  273. try
  274. {
  275. var id = 1001;
  276. parent3.Delete(_ => _.ParentID2 > 1000);
  277. parent3.Insert(() => new Parent3() { ParentID2 = id, Value = id});
  278. Assert.AreEqual(1, parent3.Where(_ => _.ParentID2 == id).Set(_ => _.ParentID2, id+1).Set(_ => _.Value, _ => _.ParentID2).Update());
  279. var obj = parent3.FirstOrDefault(_ => _.ParentID2 == id + 1);
  280. Assert.IsNotNull(obj);
  281. db.Update(obj);
  282. }
  283. finally
  284. {
  285. parent3.Delete(_ => _.ParentID2 > 1000);
  286. }
  287. });
  288. }
  289. [Test]
  290. public void UpdateAssociation1([DataContexts(ProviderName.Sybase, ProviderName.Informix)] string context)
  291. {
  292. using (var db = GetDataContext(context))
  293. {
  294. const int childId = 10000;
  295. const int parentId = 20000;
  296. try
  297. {
  298. db.Child. Delete(x => x.ChildID == childId);
  299. db.Parent.Delete(x => x.ParentID == parentId);
  300. db.Parent.Insert(() => new Parent { ParentID = parentId, Value1 = parentId });
  301. db.Child. Insert(() => new Child { ChildID = childId, ParentID = parentId });
  302. var parents =
  303. from child in db.Child
  304. where child.ChildID == childId
  305. select child.Parent;
  306. Assert.AreEqual(1, parents.Update(db.Parent, x => new Parent { Value1 = 5 }));
  307. }
  308. finally
  309. {
  310. db.Child. Delete(x => x.ChildID == childId);
  311. db.Parent.Delete(x => x.ParentID == parentId);
  312. }
  313. }
  314. }
  315. [Test]
  316. public void UpdateAssociation2([DataContexts(ProviderName.Sybase, ProviderName.Informix)] string context)
  317. {
  318. using (var db = GetDataContext(context))
  319. {
  320. const int childId = 10000;
  321. const int parentId = 20000;
  322. try
  323. {
  324. db.Child. Delete(x => x.ChildID == childId);
  325. db.Parent.Delete(x => x.ParentID == parentId);
  326. db.Parent.Insert(() => new Parent { ParentID = parentId, Value1 = parentId });
  327. db.Child. Insert(() => new Child { ChildID = childId, ParentID = parentId });
  328. var parents =
  329. from child in db.Child
  330. where child.ChildID == childId
  331. select child.Parent;
  332. Assert.AreEqual(1, parents.Update(x => new Parent { Value1 = 5 }));
  333. }
  334. finally
  335. {
  336. db.Child. Delete(x => x.ChildID == childId);
  337. db.Parent.Delete(x => x.ParentID == parentId);
  338. }
  339. }
  340. }
  341. [Test]
  342. public void UpdateAssociation3([DataContexts(ProviderName.Sybase, ProviderName.Informix)] string context)
  343. {
  344. using (var db = GetDataContext(context))
  345. {
  346. const int childId = 10000;
  347. const int parentId = 20000;
  348. try
  349. {
  350. db.Child. Delete(x => x.ChildID == childId);
  351. db.Parent.Delete(x => x.ParentID == parentId);
  352. db.Parent.Insert(() => new Parent { ParentID = parentId, Value1 = parentId });
  353. db.Child. Insert(() => new Child { ChildID = childId, ParentID = parentId });
  354. var parents =
  355. from child in db.Child
  356. where child.ChildID == childId
  357. select child.Parent;
  358. Assert.AreEqual(1, parents.Update(x => x.ParentID > 0, x => new Parent { Value1 = 5 }));
  359. }
  360. finally
  361. {
  362. db.Child. Delete(x => x.ChildID == childId);
  363. db.Parent.Delete(x => x.ParentID == parentId);
  364. }
  365. }
  366. }
  367. [Test]
  368. public void UpdateAssociation4([DataContexts(ProviderName.Sybase, ProviderName.Informix)] string context)
  369. {
  370. using (var db = GetDataContext(context))
  371. {
  372. const int childId = 10000;
  373. const int parentId = 20000;
  374. try
  375. {
  376. db.Child. Delete(x => x.ChildID == childId);
  377. db.Parent.Delete(x => x.ParentID == parentId);
  378. db.Parent.Insert(() => new Parent { ParentID = parentId, Value1 = parentId });
  379. db.Child. Insert(() => new Child { ChildID = childId, ParentID = parentId });
  380. var parents =
  381. from child in db.Child
  382. where child.ChildID == childId
  383. select child.Parent;
  384. Assert.AreEqual(1, parents.Set(x => x.Value1, 5).Update());
  385. }
  386. finally
  387. {
  388. db.Child. Delete(x => x.ChildID == childId);
  389. db.Parent.Delete(x => x.ParentID == parentId);
  390. }
  391. }
  392. }
  393. static readonly Func<TestDbManager,int,string,int> _updateQuery =
  394. CompiledQuery.Compile <TestDbManager,int,string,int>((ctx,key,value) =>
  395. ctx.Person
  396. .Where(_ => _.ID == key)
  397. .Set(_ => _.FirstName, value)
  398. .Update());
  399. [Test]
  400. public void CompiledUpdate()
  401. {
  402. using (var ctx = new TestDbManager())
  403. {
  404. _updateQuery(ctx, 12345, "54321");
  405. }
  406. }
  407. #pragma warning disable 0649
  408. [TableName("LinqDataTypes")]
  409. class Table1
  410. {
  411. public int ID;
  412. public bool BoolValue;
  413. [Association(ThisKey = "ID", OtherKey = "ParentID", CanBeNull = false)]
  414. public List<Table2> Tables2;
  415. }
  416. [TableName("Parent")]
  417. class Table2
  418. {
  419. public int ParentID;
  420. public bool Value1;
  421. [Association(ThisKey = "ParentID", OtherKey = "ID", CanBeNull = false)]
  422. public Table1 Table1;
  423. }
  424. #pragma warning restore 0649
  425. [Test]
  426. public void UpdateAssociation5([DataContexts(
  427. ProviderName.Access, ProviderName.DB2, ProviderName.Firebird, ProviderName.Informix, "Oracle", ProviderName.OracleManaged, ProviderName.PostgreSQL, ProviderName.SqlCe, ProviderName.SQLite,
  428. ExcludeLinqService=true)] string context)
  429. {
  430. using (var db = new DbManager(context))
  431. {
  432. var ids = new[] { 10000, 20000 };
  433. db.GetTable<Table2>()
  434. .Where (x => ids.Contains(x.ParentID))
  435. .Select(x => x.Table1)
  436. .Distinct()
  437. .Set(y => y.BoolValue, y => y.Tables2.All(x => x.Value1))
  438. .Update();
  439. var idx = db.LastQuery.IndexOf("INNER JOIN");
  440. Assert.That(idx, Is.Not.EqualTo(-1));
  441. idx = db.LastQuery.IndexOf("INNER JOIN", idx + 1);
  442. Assert.That(idx, Is.EqualTo(-1));
  443. }
  444. }
  445. [Test]
  446. public void AsUpdatableTest([DataContexts(ProviderName.Informix)] string context)
  447. {
  448. using (var db = GetDataContext(context))
  449. {
  450. try
  451. {
  452. var id = 1001;
  453. db.Child.Delete(c => c.ChildID > 1000);
  454. db.Child.Insert(() => new Child { ParentID = 1, ChildID = id});
  455. Assert.AreEqual(1, db.Child.Count(c => c.ChildID == id));
  456. var q = db.Child.Where(c => c.ChildID == id && c.Parent.Value1 == 1);
  457. var uq = q.AsUpdatable();
  458. uq = uq.Set(c => c.ChildID, c => c.ChildID + 1);
  459. Assert.AreEqual(1, uq.Update());
  460. Assert.AreEqual(1, db.Child.Count(c => c.ChildID == id + 1));
  461. }
  462. finally
  463. {
  464. db.Child.Delete(c => c.ChildID > 1000);
  465. }
  466. }
  467. }
  468. [TableName("GrandChild")]
  469. class Table3
  470. {
  471. [PrimaryKey(1)] public int? ParentID;
  472. [PrimaryKey(2)] public int? ChildID;
  473. public int? GrandChildID;
  474. }
  475. [Test]
  476. public void UpdateNullablePrimaryKey([DataContexts] string context)
  477. {
  478. using (var db = GetDataContext(context))
  479. {
  480. db.Update(new Table3 { ParentID = 10000, ChildID = null, GrandChildID = 1000 });
  481. if (db is DbManager)
  482. Assert.IsTrue(((DbManager)db).LastQuery.Contains("IS NULL"));
  483. db.Update(new Table3 { ParentID = 10000, ChildID = 111, GrandChildID = 1000 });
  484. if (db is DbManager)
  485. Assert.IsFalse(((DbManager)db).LastQuery.Contains("IS NULL"));
  486. }
  487. }
  488. public class TestObject
  489. {
  490. public int Value { get; set; }
  491. }
  492. [TableName("TestIdentity")]
  493. public class Table4
  494. {
  495. [PrimaryKey, MapField("ID"), Identity]
  496. public int Id;
  497. [MemberMapper(typeof(JSONSerialisationMapper))]
  498. [MapField("StringValue"), DbType(DbType.String)]
  499. public TestObject Object;
  500. }
  501. [Test]
  502. public void UpdateComplexField()
  503. {
  504. ForEachProvider(db =>
  505. {
  506. var table = db.GetTable<Table4>();
  507. int id = 3;
  508. try
  509. {
  510. var obj = new Table4();
  511. obj.Object = new TestObject() {Value = 101};
  512. obj.Id = id = Convert.ToInt32(db.InsertWithIdentity(obj));
  513. var obj2 = table.First(_ => _.Id == id);
  514. Assert.AreEqual(obj.Object.Value, obj2.Object.Value);
  515. obj.Object.Value = 999;
  516. db.Update(obj);
  517. obj2 = table.First(_ => _.Id == id);
  518. Assert.AreEqual(obj.Object.Value, obj2.Object.Value);
  519. obj.Object.Value = 666;
  520. table
  521. .Where(_ => _.Id == id)
  522. .Set(_ => _.Object, _ => obj.Object)
  523. .Update();
  524. obj2 = table.First(_ => _.Id == id);
  525. Assert.AreEqual(obj.Object.Value, obj2.Object.Value);
  526. obj.Object.Value = 777;
  527. table
  528. .Where(_ => _.Id == id)
  529. .Set(_ => _.Object, obj.Object)
  530. .Update();
  531. obj2 = table.First(_ => _.Id == id);
  532. Assert.AreEqual(obj.Object.Value, obj2.Object.Value);
  533. var id2 = Convert.ToInt32(table.InsertWithIdentity(() => new Table4
  534. {
  535. Object = new TestObject() {Value = 300}
  536. }));
  537. obj2 = table.First(_ => _.Id == id2);
  538. Assert.AreEqual(300, obj2.Object.Value);
  539. var id3 = Convert.ToInt32(table.Value(_ => _.Object, () => obj.Object)
  540. .InsertWithIdentity());
  541. obj2 = table.First(_ => _.Id == id3);
  542. Assert.AreEqual(obj.Object.Value, obj2.Object.Value);
  543. var id4 = Convert.ToInt32(table.Value(_ => _.Object, obj.Object)
  544. .InsertWithIdentity());
  545. obj2 = table.First(_ => _.Id == id4);
  546. Assert.AreEqual(obj.Object.Value, obj2.Object.Value);
  547. }
  548. finally
  549. {
  550. table.Delete(_ => _.Id >= id);
  551. }
  552. });
  553. }
  554. [TableName("LinqDataTypes")]
  555. public class LinqDataTypes3
  556. {
  557. [PrimaryKey]
  558. public int ID;
  559. public DateTime DateTimeValue;
  560. public DateTime? DateTimeValue2;
  561. }
  562. [Test]
  563. public void Update15()
  564. {
  565. ForEachProvider(db =>
  566. {
  567. var table = db.GetTable<LinqDataTypes3>();
  568. var date1 = new DateTime(2000, 1, 1);
  569. var date2 = new DateTime(2001, 1, 1);
  570. var date3 = new DateTime(2002, 1, 1);
  571. var obj = new LinqDataTypes3()
  572. {
  573. ID = 1000,
  574. DateTimeValue = date1,
  575. DateTimeValue2 = date1
  576. };
  577. table.Delete(_ => _.ID == obj.ID);
  578. db.Insert(obj);
  579. table
  580. .Where(_ => _.ID == obj.ID)
  581. .Set(_ => _.DateTimeValue, date2)
  582. .Set(_ => _.DateTimeValue2, date3)
  583. .Update();
  584. var res = table.First(_ => _.ID == obj.ID);
  585. Assert.AreEqual(date2, res.DateTimeValue);
  586. Assert.AreEqual(date3, res.DateTimeValue2);
  587. table
  588. .Where(_ => _.ID == obj.ID)
  589. .Set(_ => _.DateTimeValue, date3)
  590. .Set(_ => _.DateTimeValue2, date2)
  591. .Update();
  592. res = table.First(_ => _.ID == obj.ID);
  593. Assert.AreEqual(date3, res.DateTimeValue);
  594. Assert.AreEqual(date2, res.DateTimeValue2);
  595. });
  596. }
  597. [Test]
  598. public void Issue331()
  599. {
  600. // "OdpManaged" doesn't support XML type
  601. ForEachProvider(new[] { "PostgreSQL", ProviderName.OracleManaged }, dc =>
  602. {
  603. var db = dc as DbManager;
  604. if (db == null)
  605. return;
  606. var id = BLToolkit.Common.Convert.ToInt32(db.InsertWithIdentity(new DataTypeTest3()));
  607. var values = db.GetTable<DataTypeTest3>().ToList();
  608. db.Update<DataTypeTest3>(values);
  609. var s = values.First(_ => _.DataTypeID == 2);
  610. var o = values.First(_ => _.DataTypeID == id);
  611. db.MappingSchema.MapObjectToObject(s, o);
  612. o.DataTypeID = id;
  613. Assert.AreEqual(s.String_, o.String_);
  614. Assert.AreEqual(s.Decimal_, o.Decimal_);
  615. db.Update<DataTypeTest3>(values);
  616. o = db.GetTable<DataTypeTest3>().First(_ => _.DataTypeID == id);
  617. Assert.AreEqual(s.String_, o.String_);
  618. Assert.AreEqual(s.Decimal_, o.Decimal_);
  619. });
  620. }
  621. }
  622. }