|
9 | 9 |
|
10 | 10 |
|
11 | 11 | using System.Collections;
|
| 12 | +using System.Collections.Generic; |
12 | 13 | using System.Linq;
|
13 | 14 | using NHibernate.Cfg;
|
14 | 15 | using NHibernate.Intercept;
|
@@ -81,6 +82,7 @@ protected override void OnTearDown()
|
81 | 82 | using (var s = OpenSession())
|
82 | 83 | using (var tx = s.BeginTransaction())
|
83 | 84 | {
|
| 85 | + s.CreateQuery("delete from Word").ExecuteUpdate(); |
84 | 86 | s.CreateQuery("delete from Book").ExecuteUpdate();
|
85 | 87 | tx.Commit();
|
86 | 88 | }
|
@@ -345,5 +347,56 @@ public async Task CacheShouldNotContainLazyPropertiesAsync()
|
345 | 347 | Assert.That(NHibernateUtil.IsPropertyInitialized(book, "ALotOfText"), Is.False);
|
346 | 348 | Assert.That(NHibernateUtil.IsPropertyInitialized(book, "Image"), Is.False);
|
347 | 349 | }
|
| 350 | + |
| 351 | + [Test] |
| 352 | + public async Task CanMergeTransientWithLazyPropertyInCollectionAsync() |
| 353 | + { |
| 354 | + Book book; |
| 355 | + |
| 356 | + using (var s = OpenSession()) |
| 357 | + using (var tx = s.BeginTransaction()) |
| 358 | + { |
| 359 | + book = new Book |
| 360 | + { |
| 361 | + Name = "some name two", |
| 362 | + Id = 3, |
| 363 | + ALotOfText = "a lot of text two..." |
| 364 | + }; |
| 365 | + // This should insert a new entity. |
| 366 | + await (s.MergeAsync(book)); |
| 367 | + await (tx.CommitAsync()); |
| 368 | + } |
| 369 | + |
| 370 | + using (var s = OpenSession()) |
| 371 | + { |
| 372 | + book = await (s.GetAsync<Book>(3)); |
| 373 | + Assert.That(book, Is.Not.Null); |
| 374 | + Assert.That(book.Name, Is.EqualTo("some name two")); |
| 375 | + Assert.That(book.ALotOfText, Is.EqualTo("a lot of text two...")); |
| 376 | + |
| 377 | + } |
| 378 | + using (var s = OpenSession()) |
| 379 | + using (var tx = s.BeginTransaction()) |
| 380 | + { |
| 381 | + book.Words = new List<Word>(); |
| 382 | + var word = new Word |
| 383 | + { |
| 384 | + Id = 2, |
| 385 | + Parent = book, |
| 386 | + Content = new byte[1] {0} |
| 387 | + }; |
| 388 | + |
| 389 | + book.Words.Add(word); |
| 390 | + await (s.MergeAsync(book)); |
| 391 | + await (tx.CommitAsync()); |
| 392 | + } |
| 393 | + |
| 394 | + using (var s = OpenSession()) |
| 395 | + { |
| 396 | + book = await (s.GetAsync<Book>(3)); |
| 397 | + Assert.That(book.Words.Any(), Is.True); |
| 398 | + Assert.That(book.Words.First().Content, Is.EqualTo(new byte[1] { 0 })); |
| 399 | + } |
| 400 | + } |
348 | 401 | }
|
349 | 402 | }
|
0 commit comments