Skip to content

Commit a354e06

Browse files
committed
Merge branch '3.4.x'
2 parents 5e78ad6 + b19a06e commit a354e06

File tree

8 files changed

+133
-5
lines changed

8 files changed

+133
-5
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using NHibernate.Mapping.ByCode;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.MappingByCode.ExpliticMappingTests
6+
{
7+
[TestFixture]
8+
public class ClassWithoutNamespaceTests
9+
{
10+
[SetUp]
11+
public void OnSetUp()
12+
{
13+
Assert.That(typeof (EntityNH3615).Namespace, Is.Null);
14+
}
15+
16+
[Test]
17+
public void ShouldBeAbleToMapClassWithoutNamespace()
18+
{
19+
var mapper = new ModelMapper();
20+
mapper.Class<EntityNH3615>(rc =>
21+
{
22+
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
23+
rc.Property(x => x.Name);
24+
});
25+
26+
Assert.DoesNotThrow(() => mapper.CompileMappingForAllExplicitlyAddedEntities());
27+
}
28+
}
29+
}
30+
31+
internal class EntityNH3615
32+
{
33+
public virtual Guid Id { get; set; }
34+
public virtual string Name { get; set; }
35+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NHibernate.Test.NHSpecificTest.NH3614
7+
{
8+
public class Entity
9+
{
10+
public virtual int Id { get; protected set; }
11+
public virtual IList<string> SomeStrings { get; set; }
12+
}
13+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using NHibernate.Linq;
7+
8+
namespace NHibernate.Test.NHSpecificTest.NH3614
9+
{
10+
[TestFixture]
11+
public class Fixture : BugTestCase
12+
{
13+
[Test]
14+
public void CanProjectListOfStrings()
15+
{
16+
int id;
17+
using (var s = OpenSession())
18+
using (var tx = s.BeginTransaction())
19+
{
20+
var testEntity = new Entity
21+
{
22+
SomeStrings = new List<string> { "Hello", "World" }
23+
};
24+
s.Save(testEntity);
25+
26+
tx.Commit();
27+
28+
id = testEntity.Id;
29+
}
30+
31+
using (var s = OpenSession())
32+
{
33+
var result = s.Query<Entity>()
34+
.Where(x => x.Id == id)
35+
.Select(x => x.SomeStrings)
36+
.ToList();
37+
38+
Assert.AreEqual(1, result.Count);
39+
40+
Assert.AreEqual(2, result.Single().Count);
41+
}
42+
43+
using (var s = OpenSession())
44+
using (var tx = s.BeginTransaction())
45+
{
46+
s.Delete("from Entity");
47+
tx.Commit();
48+
}
49+
}
50+
}
51+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
assembly="NHibernate.Test"
4+
namespace="NHibernate.Test.NHSpecificTest.NH3614">
5+
6+
<class name="Entity">
7+
<id name="Id">
8+
<generator class="native" />
9+
</id>
10+
11+
<bag name="SomeStrings" table="SomeStrings" cascade="all-delete-orphan" >
12+
<key>
13+
<column name="ParentId" />
14+
</key>
15+
<element type="System.String, mscorlib">
16+
<column name="StringValue" />
17+
</element>
18+
</bag>
19+
</class>
20+
21+
</hibernate-mapping>

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,9 @@
707707
<Compile Include="NHSpecificTest\NH3058\SampleTest.cs" />
708708
<Compile Include="NHSpecificTest\NH1818\DomainClass.cs" />
709709
<Compile Include="NHSpecificTest\NH1818\Fixture1818.cs" />
710+
<Compile Include="MappingByCode\ExpliticMappingTests\ClassWithoutNamespaceTests.cs" />
711+
<Compile Include="NHSpecificTest\NH3614\Entity.cs" />
712+
<Compile Include="NHSpecificTest\NH3614\Fixture.cs" />
710713
<Compile Include="NHSpecificTest\NH3505\Student.cs" />
711714
<Compile Include="NHSpecificTest\NH3505\Teacher.cs" />
712715
<Compile Include="NHSpecificTest\NH3505\Fixture.cs" />
@@ -3030,6 +3033,7 @@
30303033
<EmbeddedResource Include="NHSpecificTest\NH3058\Mappings.hbm.xml" />
30313034
<EmbeddedResource Include="NHSpecificTest\NH2985\Mappings.hbm.xml" />
30323035
<EmbeddedResource Include="NHSpecificTest\NH1818\Mappings.hbm.xml" />
3036+
<EmbeddedResource Include="NHSpecificTest\NH3614\Mappings.hbm.xml" />
30333037
<EmbeddedResource Include="NHSpecificTest\NH3505\Mappings.hbm.xml" />
30343038
<EmbeddedResource Include="NHSpecificTest\NH3428\Mappings.hbm.xml" />
30353039
<EmbeddedResource Include="NHSpecificTest\NH3408\Mappings.hbm.xml" />
@@ -3552,6 +3556,7 @@
35523556
<EmbeddedResource Include="DynamicEntity\Tuplizer\Customer.hbm.xml" />
35533557
</ItemGroup>
35543558
<ItemGroup>
3559+
<Folder Include="NHSpecificTest\NH3615\" />
35553560
<Folder Include="Properties\" />
35563561
</ItemGroup>
35573562
<ItemGroup>
@@ -3587,4 +3592,4 @@ if exist hibernate.cfg.xml (del hibernate.cfg.xml)
35873592
if exist "$(ProjectDir)hibernate.cfg.xml" (copy "$(ProjectDir)hibernate.cfg.xml" "hibernate.cfg.xml")
35883593
copy /y "..\..\..\NHibernate.DomainModel\ABC.hbm.xml" "ABC.hbm.xml"</PostBuildEvent>
35893594
</PropertyGroup>
3590-
</Project>
3595+
</Project>

src/NHibernate/Linq/NestedSelects/NestedSelectRewriter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ private static LambdaExpression MakePredicate(int index)
220220

221221
private static Expression GetIdentifier(ISessionFactory sessionFactory, Expression expression)
222222
{
223+
if (expression.Type.IsPrimitive || expression.Type == typeof(string))
224+
return expression;
225+
223226
var classMetadata = sessionFactory.GetClassMetadata(expression.Type);
224227
if (classMetadata == null)
225228
return Expression.Constant(null);
@@ -268,4 +271,4 @@ private static System.Type GetElementType(System.Type type)
268271
return elementType;
269272
}
270273
}
271-
}
274+
}

src/NHibernate/Mapping/ByCode/Impl/TypeNameUtil.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ public static string GetShortClassName(this System.Type type, HbmMapping mapDoc)
3434
string typeAssemblyFullName = type.Assembly.FullName;
3535
string typeNameSpace = type.Namespace;
3636
string assembly = null;
37-
if (!typeAssembly.Equals(mapDoc.assembly) && !typeAssemblyFullName.Equals(mapDoc.assembly))
37+
if (typeAssembly != mapDoc.assembly && typeAssemblyFullName != mapDoc.assembly)
3838
{
3939
assembly = typeAssembly;
4040
}
4141
string @namespace = null;
42-
if (!typeNameSpace.Equals(mapDoc.@namespace))
42+
if (typeNameSpace != mapDoc.@namespace)
4343
{
4444
@namespace = typeNameSpace;
4545
}

src/NHibernate/Mapping/ByCode/ModelMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ public HbmMapping CompileMappingFor(IEnumerable<System.Type> types)
557557
{
558558
defaultAssemblyName = firstType.Assembly.GetName().Name;
559559
}
560-
if (firstType != null && typeToMap.All(t => t.Namespace.Equals(firstType.Namespace)))
560+
if (firstType != null && typeToMap.All(t => t.Namespace == firstType.Namespace))
561561
{
562562
defaultNamespace = firstType.Namespace;
563563
}

0 commit comments

Comments
 (0)