Skip to content

Commit 4b88cc1

Browse files
committed
Merge branches 'gh-321' and 'gh-322'
3 parents 8aaff65 + a083691 + fc76758 commit 4b88cc1

File tree

7 files changed

+62
-0
lines changed

7 files changed

+62
-0
lines changed

src/NHibernate.Test/Linq/LinqQuerySamples.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ namespace NHibernate.Test.Linq
99
[TestFixture]
1010
public class LinqQuerySamples : LinqTestCase
1111
{
12+
[Test]
13+
public void GroupTwoQueriesAndSum()
14+
{
15+
//NH-3534
16+
var queryWithAggregation = from o1 in db.Orders
17+
from o2 in db.Orders
18+
where o1.Customer.CustomerId == o2.Customer.CustomerId && o1.OrderDate == o2.OrderDate
19+
group o1 by new { o1.Customer.CustomerId, o1.OrderDate } into g
20+
select new { CustomerId = g.Key.CustomerId, LastOrderDate = g.Max(x => x.OrderDate) };
21+
22+
var result = queryWithAggregation.ToList();
23+
24+
Assert.IsNotNull(result);
25+
Assert.IsNotEmpty(result);
26+
}
27+
1228
[Category("WHERE")]
1329
[Test(Description = "This sample uses WHERE to filter for Customers in London.")]
1430
public void DLinq1()

src/NHibernate.Test/MappingByCode/ExplicitMappingTests/ComponentAsIdTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ private class MyComponent : IMyCompo
2929
public string Name { get; set; }
3030
}
3131

32+
[Test]
33+
public void CanSpecifyUnsavedValue()
34+
{
35+
//NH-3048
36+
var mapper = new ModelMapper();
37+
mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id, x =>
38+
{
39+
x.UnsavedValue(UnsavedValueType.Any);
40+
}));
41+
42+
var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
43+
44+
Assert.AreEqual(mapping.RootClasses[0].CompositeId.unsavedvalue, HbmUnsavedValueType.Any);
45+
}
46+
3247
[Test]
3348
public void WhenPropertyUsedAsComposedIdThenRegister()
3449
{

src/NHibernate/Mapping/ByCode/ICompositeIdMapper.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public interface IComponentAsIdAttributesMapper : IAccessorPropertyMapper
1212
/// Useful when the property is an interface and you need the mapping to a concrete class mapped as component.
1313
/// </remarks>
1414
void Class(System.Type componentType);
15+
16+
void UnsavedValue(UnsavedValueType unsavedValueType);
1517
}
1618

1719
public interface IComponentAsIdMapper : IComponentAsIdAttributesMapper, IMinimalPlainPropertyContainerMapper { }
@@ -21,6 +23,8 @@ public interface IComposedIdMapper<TEntity> : IMinimalPlainPropertyContainerMapp
2123
public interface IComponentAsIdAttributesMapper<TComponent> : IAccessorPropertyMapper
2224
{
2325
void Class<TConcrete>() where TConcrete : TComponent;
26+
27+
void UnsavedValue(UnsavedValueType unsavedValueType);
2428
}
2529

2630
public interface IComponentAsIdMapper<TComponent> : IComponentAsIdAttributesMapper<TComponent>, IMinimalPlainPropertyContainerMapper<TComponent>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public ComponentAsIdMapper(System.Type componentType, MemberInfo declaringTypeMe
2020
accessorPropertyMapper = new AccessorPropertyMapper(declaringTypeMember.DeclaringType, declaringTypeMember.Name, x => id.access = x);
2121
}
2222

23+
public void UnsavedValue(UnsavedValueType unsavedValueType)
24+
{
25+
id.unsavedvalue = (HbmUnsavedValueType)Enum.Parse(typeof(HbmUnsavedValueType), unsavedValueType.ToString());
26+
}
27+
2328
public HbmCompositeId CompositeId
2429
{
2530
get { return id; }

src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComponentAsIdCustomizer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public ComponentAsIdCustomizer(IModelExplicitDeclarationsHolder explicitDeclarat
1919
explicitDeclarationsHolder.AddAsPoid(propertyPath.LocalMember);
2020
}
2121

22+
public void UnsavedValue(UnsavedValueType unsavedValueType)
23+
{
24+
CustomizersHolder.AddCustomizer(PropertyPath, (IComponentAsIdAttributesMapper m) => m.UnsavedValue(unsavedValueType));
25+
}
26+
2227
public void Class<TConcrete>() where TConcrete : TComponent
2328
{
2429
CustomizersHolder.AddCustomizer(PropertyPath, (IComponentAsIdAttributesMapper m) => m.Class(typeof(TConcrete)));
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NHibernate.Mapping.ByCode
7+
{
8+
public enum UnsavedValueType
9+
{
10+
Undefined,
11+
12+
Any,
13+
14+
None,
15+
}
16+
}

src/NHibernate/NHibernate.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@
498498
<Compile Include="Mapping\ByCode\NotFoundMode.cs" />
499499
<Compile Include="Mapping\ByCode\SchemaAction.cs" />
500500
<Compile Include="Mapping\ByCode\TypeExtensions.cs" />
501+
<Compile Include="Mapping\ByCode\UnsavedValueType.cs" />
501502
<Compile Include="Mapping\ByCode\VersionGeneration.cs" />
502503
<Compile Include="Mapping\Collection.cs" />
503504
<Compile Include="Mapping\Column.cs" />

0 commit comments

Comments
 (0)