Skip to content

Commit e5b11e6

Browse files
committed
Improve select clause transformation for Linq provider
1 parent 9f67be2 commit e5b11e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4742
-422
lines changed

src/NHibernate.DomainModel/Northwind/Entities/Animal.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public class Animal
1212
public virtual Animal Father { get; set; }
1313
public virtual IList<Animal> Children { get; set; }
1414
public virtual string SerialNumber { get; set; }
15-
15+
public virtual string FatherSerialNumber => Father?.SerialNumber;
16+
public virtual bool HasFather => Father != null;
1617
public virtual Animal FatherOrMother => Father ?? Mother;
1718
}
1819

src/NHibernate.DomainModel/Northwind/Entities/Role.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ public class Role
77
public virtual bool IsActive { get; set; }
88
public virtual AnotherEntity Entity { get; set; }
99
public virtual Role ParentRole { get; set; }
10+
public virtual User CreatedBy { get; set; } // Not mapped
1011
}
1112
}

src/NHibernate.DomainModel/Northwind/Entities/UserComponent.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ public class UserComponent
55
public string Property1 { get; set; }
66
public string Property2 { get; set; }
77
public UserComponent2 OtherComponent { get; set; }
8+
9+
public string Property3 => $"{Property1}{Property2}";
810
}
911

1012
public class UserComponent2
1113
{
1214
public string OtherProperty1 { get; set; }
15+
16+
public string OtherProperty2 => OtherProperty1;
1317
}
14-
}
18+
}

src/NHibernate.DomainModel/Northwind/Entities/UserDto.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23

34
namespace NHibernate.DomainModel.Northwind.Entities
45
{
@@ -9,11 +10,13 @@ public class UserDto
910
public virtual int InvalidLoginAttempts { get; set; }
1011
public virtual string RoleName { get; set; }
1112
public virtual UserDto2 Dto2 { get; set; }
13+
public virtual List<UserDto2> Dto2List { get; set; } = new List<UserDto2>();
1214

1315
public UserDto(int id, string name)
1416
{
1517
Id = id;
1618
Name = name;
19+
Dto2 = new UserDto2();
1720
}
1821
}
1922

src/NHibernate.Test/Async/Linq/SelectionTests.cs

Lines changed: 1005 additions & 19 deletions
Large diffs are not rendered by default.

src/NHibernate.Test/Async/TypedManyToOne/TypedManyToOneTest.cs

Lines changed: 75 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99

1010

1111
using System.Collections;
12+
using System.Linq;
1213
using NHibernate.Dialect;
1314
using NUnit.Framework;
15+
using NHibernate.Linq;
1416

1517
namespace NHibernate.Test.TypedManyToOne
1618
{
1719
using System.Threading.Tasks;
20+
using System.Threading;
1821
[TestFixture]
1922
public class TypedManyToOneTestAsync : TestCase
2023
{
@@ -35,38 +38,27 @@ protected override bool AppliesTo(Dialect.Dialect dialect)
3538
}
3639

3740
[Test]
38-
public async Task TestCreateQueryAsync()
41+
public async Task TestLinqEntityNameQueryAsync()
3942
{
40-
var cust = new Customer();
41-
cust.CustomerId = "abc123";
42-
cust.Name = "Matt";
43-
44-
var ship = new Address();
45-
ship.Street = "peachtree rd";
46-
ship.State = "GA";
47-
ship.City = "ATL";
48-
ship.Zip = "30326";
49-
ship.AddressId = new AddressId("SHIPPING", "xyz123");
50-
ship.Customer = cust;
51-
52-
var bill = new Address();
53-
bill.Street = "peachtree rd";
54-
bill.State = "GA";
55-
bill.City = "ATL";
56-
bill.Zip = "30326";
57-
bill.AddressId = new AddressId("BILLING", "xyz123");
58-
bill.Customer = cust;
59-
60-
cust.BillingAddress = bill;
61-
cust.ShippingAddress = ship;
62-
63-
using (ISession s = Sfi.OpenSession())
64-
using (ITransaction t = s.BeginTransaction())
43+
var cust = await (CreateCustomerAsync());
44+
using (var s = Sfi.OpenSession())
45+
using (var t = s.BeginTransaction())
6546
{
66-
await (s.PersistAsync(cust));
47+
var billingNotes = await (s.Query<Customer>().Select(o => o.BillingAddress.BillingNotes).FirstAsync());
48+
Assert.That(billingNotes, Is.EqualTo("BillingNotes"));
49+
var shippingNotes = await (s.Query<Customer>().Select(o => o.ShippingAddress.ShippingNotes).FirstAsync());
50+
Assert.That(shippingNotes, Is.EqualTo("ShippingNotes"));
51+
6752
await (t.CommitAsync());
6853
}
6954

55+
await (DeleteCustomerAsync(cust));
56+
}
57+
58+
[Test]
59+
public async Task TestCreateQueryAsync()
60+
{
61+
var cust = await (CreateCustomerAsync());
7062
using (ISession s = Sfi.OpenSession())
7163
using (ITransaction t = s.BeginTransaction())
7264
{
@@ -82,20 +74,7 @@ public async Task TestCreateQueryAsync()
8274
await (t.CommitAsync());
8375
}
8476

85-
using (ISession s = Sfi.OpenSession())
86-
using (ITransaction t = s.BeginTransaction())
87-
{
88-
await (s.SaveOrUpdateAsync(cust));
89-
ship = cust.ShippingAddress;
90-
cust.ShippingAddress = null;
91-
await (s.DeleteAsync("ShippingAddress", ship));
92-
await (s.FlushAsync());
93-
94-
Assert.That(await (s.GetAsync("ShippingAddress", ship.AddressId)), Is.Null);
95-
await (s.DeleteAsync(cust));
96-
97-
await (t.CommitAsync());
98-
}
77+
await (DeleteCustomerAsync(cust));
9978
}
10079

10180
[Test]
@@ -124,5 +103,60 @@ public async Task TestCreateQueryNullAsync()
124103
await (t.CommitAsync());
125104
}
126105
}
106+
107+
private async Task<Customer> CreateCustomerAsync(CancellationToken cancellationToken = default(CancellationToken))
108+
{
109+
var cust = new Customer();
110+
cust.CustomerId = "abc123";
111+
cust.Name = "Matt";
112+
113+
var ship = new Address();
114+
ship.Street = "peachtree rd";
115+
ship.State = "GA";
116+
ship.City = "ATL";
117+
ship.Zip = "30326";
118+
ship.AddressId = new AddressId("SHIPPING", "xyz123");
119+
ship.Customer = cust;
120+
ship.ShippingNotes = "ShippingNotes";
121+
122+
var bill = new Address();
123+
bill.Street = "peachtree rd";
124+
bill.State = "GA";
125+
bill.City = "ATL";
126+
bill.Zip = "30326";
127+
bill.AddressId = new AddressId("BILLING", "xyz123");
128+
bill.Customer = cust;
129+
bill.BillingNotes = "BillingNotes";
130+
131+
cust.BillingAddress = bill;
132+
cust.ShippingAddress = ship;
133+
134+
using (ISession s = Sfi.OpenSession())
135+
using (ITransaction t = s.BeginTransaction())
136+
{
137+
await (s.PersistAsync(cust, cancellationToken));
138+
await (t.CommitAsync(cancellationToken));
139+
}
140+
141+
return cust;
142+
}
143+
144+
private async Task DeleteCustomerAsync(Customer cust, CancellationToken cancellationToken = default(CancellationToken))
145+
{
146+
using (var s = Sfi.OpenSession())
147+
using (var t = s.BeginTransaction())
148+
{
149+
await (s.SaveOrUpdateAsync(cust, cancellationToken));
150+
var ship = cust.ShippingAddress;
151+
cust.ShippingAddress = null;
152+
await (s.DeleteAsync("ShippingAddress", ship, cancellationToken));
153+
await (s.FlushAsync(cancellationToken));
154+
155+
Assert.That(await (s.GetAsync("ShippingAddress", ship.AddressId, cancellationToken)), Is.Null);
156+
await (s.DeleteAsync(cust, cancellationToken));
157+
158+
await (t.CommitAsync(cancellationToken));
159+
}
160+
}
127161
}
128162
}

0 commit comments

Comments
 (0)