Skip to content

Commit adc1aaf

Browse files
SlyNetfredericDelaporte
authored andcommitted
Test Parent property is not accessible in queries (#1584)
Test for #1583
1 parent af5e6fa commit adc1aaf

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System.Collections.Generic;
12+
using System.Linq;
13+
using NHibernate.Cfg.MappingSchema;
14+
using NHibernate.Mapping.ByCode;
15+
using NUnit.Framework;
16+
using NHibernate.Linq;
17+
18+
namespace NHibernate.Test.NHSpecificTest.GH1583
19+
{
20+
using System.Threading.Tasks;
21+
22+
[TestFixture]
23+
public class FixtureAsync : TestCaseMappingByCode
24+
{
25+
protected override HbmMapping GetMappings()
26+
{
27+
var mapper = new ModelMapper();
28+
mapper.Class<Parent>(rc =>
29+
{
30+
rc.Id(x => x.ParentId, m => m.Generator(Generators.HighLow));
31+
rc.List(
32+
x => x.Children,
33+
listMap =>
34+
{
35+
listMap.Table("Children");
36+
listMap.Index(index => index.Column("SortIndex"));
37+
38+
listMap.Key(keyMap =>
39+
{
40+
keyMap.Column(clm =>
41+
{
42+
clm.Name("ParentId");
43+
});
44+
});
45+
listMap.Lazy(CollectionLazy.Lazy);
46+
listMap.Cascade(Mapping.ByCode.Cascade.All | Mapping.ByCode.Cascade.All);
47+
listMap.Inverse(true);
48+
},
49+
rel => { rel.Component(cmp => { cmp.Parent(x => x.ParentLink); }); }
50+
);
51+
});
52+
53+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
54+
}
55+
56+
[Test]
57+
[KnownBug("GH-1583")]
58+
public async Task QueryForPropertyOfParentInComponentAsync()
59+
{
60+
using (var session = OpenSession())
61+
using (session.BeginTransaction())
62+
{
63+
var result = await ((from p in session.Query<Parent>().SelectMany(x => x.Children)
64+
select p.ParentLink.ParentId).ToListAsync());
65+
66+
Assert.That(result, Is.Empty);
67+
}
68+
}
69+
}
70+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using NHibernate.Cfg.MappingSchema;
4+
using NHibernate.Mapping.ByCode;
5+
using NUnit.Framework;
6+
7+
namespace NHibernate.Test.NHSpecificTest.GH1583
8+
{
9+
public class Parent
10+
{
11+
public virtual int ParentId { get; set; }
12+
public virtual IList<Child> Children { get; set; }
13+
}
14+
15+
public class Child
16+
{
17+
public virtual Parent ParentLink { get; set; }
18+
}
19+
20+
[TestFixture]
21+
public class Fixture : TestCaseMappingByCode
22+
{
23+
protected override HbmMapping GetMappings()
24+
{
25+
var mapper = new ModelMapper();
26+
mapper.Class<Parent>(rc =>
27+
{
28+
rc.Id(x => x.ParentId, m => m.Generator(Generators.HighLow));
29+
rc.List(
30+
x => x.Children,
31+
listMap =>
32+
{
33+
listMap.Table("Children");
34+
listMap.Index(index => index.Column("SortIndex"));
35+
36+
listMap.Key(keyMap =>
37+
{
38+
keyMap.Column(clm =>
39+
{
40+
clm.Name("ParentId");
41+
});
42+
});
43+
listMap.Lazy(CollectionLazy.Lazy);
44+
listMap.Cascade(Mapping.ByCode.Cascade.All | Mapping.ByCode.Cascade.All);
45+
listMap.Inverse(true);
46+
},
47+
rel => { rel.Component(cmp => { cmp.Parent(x => x.ParentLink); }); }
48+
);
49+
});
50+
51+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
52+
}
53+
54+
[Test]
55+
[KnownBug("GH-1583")]
56+
public void QueryForPropertyOfParentInComponent()
57+
{
58+
using (var session = OpenSession())
59+
using (session.BeginTransaction())
60+
{
61+
var result = (from p in session.Query<Parent>().SelectMany(x => x.Children)
62+
select p.ParentLink.ParentId).ToList();
63+
64+
Assert.That(result, Is.Empty);
65+
}
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)