Skip to content

Commit 559d844

Browse files
committed
Merge tag '4.0.4.GA'
# Conflicts: # src/NHibernate/Impl/ExpressionProcessor.cs
2 parents 9c058af + 2c5cb3d commit 559d844

File tree

5 files changed

+168
-3
lines changed

5 files changed

+168
-3
lines changed

build-common/common.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
effectively SP0).
6161
-->
6262

63-
<property name="project.version" value="4.0.3.GA" overwrite="false" />
63+
<property name="project.version" value="4.0.4.GA" overwrite="false" />
6464

6565
<!-- This version number should be changed if, but only if, there are incompatible
6666
changes compared to the previous version. -->

releasenotes.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
Build 4.0.3.GA
1+
Build 4.0.4.GA
22
=============================
33

4+
** Bug
5+
* [NH-3795] - C# compiler "Roslyn" regression
6+
7+
8+
Build 4.0.3.GA
9+
=============================
410

511
** Bug
612
* [NH-2504] - Can't use Cacheable with Group By
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
using System.Collections;
2+
using NHibernate.DomainModel;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.NHSpecificTest.NH3795
6+
{
7+
/// <summary>
8+
/// Tests in this class only failed when the code was build with the Roslyn compiler which is included in Visual Studio 2015
9+
/// </summary>
10+
[TestFixture]
11+
public class Fixture : TestCase
12+
{
13+
protected Child childAliasField = null;
14+
protected A aAliasField = null;
15+
16+
protected override IList Mappings
17+
{
18+
get { return new[] {"ParentChild.hbm.xml", "ABC.hbm.xml"}; }
19+
}
20+
21+
[Test]
22+
public void TestFieldAliasInQueryOver()
23+
{
24+
using (var s = sessions.OpenSession())
25+
{
26+
A rowalias = null;
27+
s.QueryOver(() => aAliasField)
28+
.SelectList(list => list
29+
.Select(() => aAliasField.Id).WithAlias(() => rowalias.Id))
30+
.List();
31+
}
32+
}
33+
34+
[Test]
35+
public void TestFieldAliasInQueryOverWithConversion()
36+
{
37+
using (var s = sessions.OpenSession())
38+
{
39+
B rowalias = null;
40+
s.QueryOver(() => aAliasField)
41+
.SelectList(list => list
42+
.Select(() => ((B)aAliasField).Count).WithAlias(() => rowalias.Count))
43+
.List();
44+
}
45+
}
46+
47+
[Test]
48+
public void TestFieldAliasInJoinAlias()
49+
{
50+
using (var s = sessions.OpenSession())
51+
{
52+
Child rowalias = null;
53+
s.QueryOver<Parent>()
54+
.JoinAlias(p => p.Child, () => childAliasField)
55+
.SelectList(list => list
56+
.Select(() => childAliasField.Id).WithAlias(() => rowalias.Id))
57+
.List();
58+
}
59+
}
60+
61+
[Test]
62+
public void TestFieldAliasInJoinQueryOver()
63+
{
64+
using (var s = sessions.OpenSession())
65+
{
66+
Child rowalias = null;
67+
s.QueryOver<Parent>()
68+
.JoinQueryOver(p => p.Child, () => childAliasField)
69+
.SelectList(list => list
70+
.Select(() => childAliasField.Id).WithAlias(() => rowalias.Id))
71+
.List();
72+
}
73+
}
74+
75+
[Test]
76+
public void TestAliasInQueryOver()
77+
{
78+
Child childAlias = null;
79+
A aAlias = null;
80+
using (var s = sessions.OpenSession())
81+
{
82+
A rowalias = null;
83+
s.QueryOver(() => aAlias)
84+
.SelectList(list => list
85+
.Select(() => aAlias.Id).WithAlias(() => rowalias.Id))
86+
.List();
87+
}
88+
}
89+
90+
[Test]
91+
public void TestAliasInQueryOverWithConversion()
92+
{
93+
Child childAlias = null;
94+
A aAlias = null;
95+
using (var s = sessions.OpenSession())
96+
{
97+
B rowalias = null;
98+
s.QueryOver(() => aAlias)
99+
.SelectList(list => list
100+
.Select(() => ((B) aAlias).Count).WithAlias(() => rowalias.Count))
101+
.List();
102+
}
103+
}
104+
105+
[Test]
106+
public void TestAliasInJoinAlias()
107+
{
108+
Child childAlias = null;
109+
A aAlias = null;
110+
using (var s = sessions.OpenSession())
111+
{
112+
Child rowalias = null;
113+
s.QueryOver<Parent>()
114+
.JoinAlias(p => p.Child, () => childAlias)
115+
.SelectList(list => list
116+
.Select(() => childAlias.Id).WithAlias(() => rowalias.Id))
117+
.List();
118+
}
119+
}
120+
121+
[Test]
122+
public void TestAliasInJoinQueryOver()
123+
{
124+
Child childAlias = null;
125+
A aAlias = null;
126+
using (var s = sessions.OpenSession())
127+
{
128+
Child rowalias = null;
129+
s.QueryOver<Parent>()
130+
.JoinQueryOver(p => p.Child, () => childAlias)
131+
.SelectList(list => list
132+
.Select(() => childAlias.Id).WithAlias(() => rowalias.Id))
133+
.List();
134+
}
135+
}
136+
}
137+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,7 @@
871871
<Compile Include="NHSpecificTest\NH3634\PersonMapper.cs" />
872872
<Compile Include="NHSpecificTest\NH3727\Entity.cs" />
873873
<Compile Include="NHSpecificTest\NH3727\FixtureByCode.cs" />
874+
<Compile Include="NHSpecificTest\NH3795\Fixture.cs" />
874875
<Compile Include="NHSpecificTest\NH646\Domain.cs" />
875876
<Compile Include="NHSpecificTest\NH646\Fixture.cs" />
876877
<Compile Include="NHSpecificTest\NH3234\Fixture.cs" />

src/NHibernate/Impl/ExpressionProcessor.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
using System.Linq;
55
using System.Linq.Expressions;
66
using System.Reflection;
7-
7+
using System.Runtime.CompilerServices;
8+
using System.Text.RegularExpressions;
89
using NHibernate.Criterion;
910
using NHibernate.Util;
1011
using Expression = System.Linq.Expressions.Expression;
@@ -290,6 +291,21 @@ public static ProjectionInfo FindMemberProjection(Expression expression)
290291
return ProjectionInfo.ForProperty(FindMemberExpression(expression));
291292
}
292293

294+
//http://stackoverflow.com/a/2509524/259946
295+
private static readonly Regex GeneratedMemberNameRegex = new Regex(@"^(CS\$)?<\w*>[1-9a-s]__[a-zA-Z]+[0-9]*$", RegexOptions.Compiled | RegexOptions.Singleline);
296+
297+
private static bool IsCompilerGeneratedMemberExpressionOfCompilerGeneratedClass(Expression expression)
298+
{
299+
var memberExpression = expression as MemberExpression;
300+
if (memberExpression != null && memberExpression.Member.DeclaringType != null)
301+
{
302+
return Attribute.GetCustomAttribute(memberExpression.Member.DeclaringType, typeof(CompilerGeneratedAttribute)) != null
303+
&& GeneratedMemberNameRegex.IsMatch(memberExpression.Member.Name);
304+
}
305+
306+
return false;
307+
}
308+
293309
/// <summary>
294310
/// Retrieves the name of the property from a member expression
295311
/// </summary>
@@ -314,6 +330,11 @@ public static string FindMemberExpression(Expression expression)
314330
return FindMemberExpression(parentExpression);
315331
}
316332

333+
if (IsCompilerGeneratedMemberExpressionOfCompilerGeneratedClass(parentExpression))
334+
{
335+
return memberExpression.Member.Name;
336+
}
337+
317338
return FindMemberExpression(parentExpression) + "." + memberExpression.Member.Name;
318339
}
319340
if (IsConversion(parentExpression.NodeType))

0 commit comments

Comments
 (0)