-
Notifications
You must be signed in to change notification settings - Fork 934
Fetch requests do not work with collection projections #2341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
05986c2
324d6ec
5c3946c
683286b
e61f097
0bb091f
7fce0ce
330ebf0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
using System.Collections.Generic; | ||
using System.Linq; | ||
using NHibernate.DomainModel.Northwind.Entities; | ||
using NHibernate.Linq; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.Linq | ||
|
@@ -211,6 +212,14 @@ public void CanProjectManyCollections() | |
var result = query.ToList(); | ||
Assert.That(result.Count, Is.EqualTo(2155)); | ||
} | ||
|
||
[Test] | ||
public void CanProjectManyCollectionsWithFetch() | ||
{ | ||
var query = db.Orders.FetchMany(o => o.OrderLines).SelectMany(o => o.OrderLines); | ||
var result = query.ToList(); | ||
Assert.That(result.Count, Is.EqualTo(2155)); | ||
} | ||
|
||
[Test] | ||
public void CanProjectCollections() | ||
|
@@ -220,6 +229,14 @@ public void CanProjectCollections() | |
Assert.That(result.Count, Is.EqualTo(830)); | ||
} | ||
|
||
[Test] | ||
public void CanProjectCollectionsWithFetch() | ||
{ | ||
var query = db.Orders.Fetch(o => o.OrderLines).Select(o => o.OrderLines); | ||
var result = query.ToList(); | ||
Assert.That(result.Count, Is.EqualTo(830)); | ||
} | ||
|
||
[Test] | ||
public void CanProjectCollectionsInsideAnonymousType() | ||
{ | ||
|
@@ -228,6 +245,14 @@ public void CanProjectCollectionsInsideAnonymousType() | |
Assert.That(result.Count, Is.EqualTo(830)); | ||
} | ||
|
||
[Test] | ||
public void CanProjectCollectionsInsideAnonymousTypeWithFetch() | ||
{ | ||
var query = db.Orders.Fetch(o => o.OrderLines).Select(o => new { o.OrderId, o.OrderLines }); | ||
var result = query.ToList(); | ||
Assert.That(result.Count, Is.EqualTo(830)); | ||
} | ||
|
||
[Test] | ||
public void ProjectAnonymousTypeWithCollection() | ||
{ | ||
|
@@ -241,6 +266,19 @@ public void ProjectAnonymousTypeWithCollection() | |
Assert.That(result[0].o.OrderLines, Is.EquivalentTo(result[0].OrderLines)); | ||
} | ||
|
||
[Test] | ||
public void ProjectAnonymousTypeWithCollectionWithFetch() | ||
{ | ||
// NH-3333 | ||
// done by WCF DS: context.Orders.Expand(o => o.OrderLines) from the client | ||
var query = from o in db.Orders.Fetch(o => o.OrderLines) | ||
select new { o, o.OrderLines }; | ||
|
||
var result = query.ToList(); | ||
Assert.That(result.Count, Is.EqualTo(830)); | ||
Assert.That(result[0].o.OrderLines, Is.EquivalentTo(result[0].OrderLines)); | ||
} | ||
|
||
[Test] | ||
public void ProjectAnonymousTypeWithCollection1() | ||
{ | ||
|
@@ -254,6 +292,19 @@ public void ProjectAnonymousTypeWithCollection1() | |
Assert.That(result[0].o.OrderLines, Is.EquivalentTo(result[0].OrderLines)); | ||
} | ||
|
||
[Test] | ||
public void ProjectAnonymousTypeWithCollection1WithFetch() | ||
{ | ||
// NH-3333 | ||
// done by WCF DS: context.Orders.Expand(o => o.OrderLines) from the client | ||
var query = from o in db.Orders.Fetch(o => o.OrderLines) | ||
select new { o.OrderLines, o }; | ||
|
||
var result = query.ToList(); | ||
Assert.That(result.Count, Is.EqualTo(830)); | ||
Assert.That(result[0].o.OrderLines, Is.EquivalentTo(result[0].OrderLines)); | ||
} | ||
|
||
[Test] | ||
public void ProjectAnonymousTypeWithCollection2() | ||
{ | ||
|
@@ -266,6 +317,18 @@ public void ProjectAnonymousTypeWithCollection2() | |
Assert.That(result.Count, Is.EqualTo(830)); | ||
} | ||
|
||
[Test] | ||
public void ProjectAnonymousTypeWithCollection2WithFetch() | ||
{ | ||
// NH-3333 | ||
// done by WCF DS: context.Orders.Expand(o => o.OrderLines) from the client | ||
var query = from o in db.Orders.Fetch(o => o.OrderLines) | ||
select new { o.OrderLines, A = 1, B = 2 }; | ||
|
||
var result = query.ToList(); | ||
Assert.That(result.Count, Is.EqualTo(830)); | ||
} | ||
|
||
[Test] | ||
public void ProjectAnonymousTypeWithCollection3() | ||
{ | ||
|
@@ -278,6 +341,18 @@ public void ProjectAnonymousTypeWithCollection3() | |
Assert.That(result.Count, Is.EqualTo(830)); | ||
} | ||
|
||
[Test] | ||
public void ProjectAnonymousTypeWithCollection3WithFetch() | ||
{ | ||
// NH-3333 | ||
// done by WCF DS: context.Orders.Expand(o => o.OrderLines) from the client | ||
var query = from o in db.Orders.Fetch(o => o.OrderLines) | ||
select new { OrderLines = o.OrderLines.ToList() }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The sql created from this query returns more than 7000 rows, I think that it would be better to use the
the same applies for other queries that were added by this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps I should just add the test from the original bug report. Since doing a Fetch when projecting a collection is actually redundant. Adding that one test will guard against a regression for this code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Fine by me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am also ok with that. |
||
|
||
var result = query.ToList(); | ||
Assert.That(result.Count, Is.EqualTo(830)); | ||
} | ||
|
||
[Test] | ||
public void ProjectKnownTypeWithCollection() | ||
{ | ||
|
@@ -294,7 +369,26 @@ public void ProjectKnownTypeWithCollection() | |
Assert.That(result.Count, Is.EqualTo(830)); | ||
Assert.That(result[0].ExpandedElement.OrderLines, Is.EquivalentTo(result[0].ProjectedProperty0)); | ||
} | ||
|
||
|
||
LodewijkSioen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[Test] | ||
public void ProjectKnownTypeWithCollectionWithFetch() | ||
{ | ||
var query = from o in db.Orders.Fetch(x => x.OrderLines) | ||
select new ExpandedWrapper<Order, ISet<OrderLine>> | ||
{ | ||
ExpandedElement = o, | ||
ProjectedProperty0 = o.OrderLines, | ||
Description = "OrderLine", | ||
ReferenceDescription = "OrderLine" | ||
}; | ||
|
||
var result = query.ToList(); | ||
Assert.That(result.Count, Is.EqualTo(830)); | ||
Assert.That(NHibernateUtil.IsInitialized(result[0].ExpandedElement.OrderLines), Is.True); | ||
Assert.That(NHibernateUtil.IsInitialized(result[0].ProjectedProperty0), Is.True); | ||
LodewijkSioen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Assert.That(result[0].ExpandedElement.OrderLines, Is.EquivalentTo(result[0].ProjectedProperty0)); | ||
} | ||
|
||
[Test] | ||
public void ProjectKnownTypeWithCollection2() | ||
{ | ||
|
Uh oh!
There was an error while loading. Please reload this page.