Skip to content

Commit 31a7ddb

Browse files
committed
NH-3779 - Allow map structures as components in mapping by code
1 parent 1fe5080 commit 31a7ddb

27 files changed

+100
-72
lines changed

src/NHibernate.Test/NHSpecificTest/NH901/Fixture.cs

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1+
using System.Collections;
2+
using NHibernate.Cfg;
3+
using NHibernate.Mapping.ByCode;
4+
using NHibernate.Type;
15
using NUnit.Framework;
26

3-
using System;
4-
using System.Collections.Generic;
5-
using System.Text;
6-
77
namespace NHibernate.Test.NHSpecificTest.NH901
88
{
9-
[TestFixture]
10-
public class Fixture : BugTestCase
9+
public abstract class FixtureBase : TestCase
1110
{
12-
public override string BugNumber
13-
{
14-
get { return "NH901"; }
15-
}
16-
1711
private new ISession OpenSession(IInterceptor interceptor)
1812
{
1913
lastOpenedSession = sessions.OpenSession(interceptor);
@@ -99,12 +93,56 @@ public void ReplaceValueTypeComponentWithSameValueDoesNotMakeItDirty()
9993
}
10094
}
10195

96+
[TestFixture]
97+
public class Fixture : FixtureBase
98+
{
99+
protected override string MappingsAssembly
100+
{
101+
get { return "NHibernate.Test"; }
102+
}
103+
104+
protected override IList Mappings
105+
{
106+
get { return new[] {"NHSpecificTest.NH901.Mappings.hbm.xml"}; }
107+
}
108+
}
109+
110+
[TestFixture]
111+
public class FixtureByCode : FixtureBase
112+
{
113+
protected override IList Mappings
114+
{
115+
get { return new string[0]; }
116+
}
117+
118+
protected override string MappingsAssembly
119+
{
120+
get { return null; }
121+
}
122+
123+
protected override void AddMappings(Configuration configuration)
124+
{
125+
var mapper = new ModelMapper();
126+
mapper.Class<Person>(rc =>
127+
{
128+
rc.Table("NH901_Person");
129+
rc.Id(x => x.Name, m => m.Generator(Generators.Assigned));
130+
rc.Component(x => x.Address, cm =>
131+
{
132+
cm.Property(x => x.City);
133+
cm.Property(x => x.Street);
134+
});
135+
});
136+
configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
137+
}
138+
}
139+
102140
public class InterceptorStub : EmptyInterceptor
103141
{
104142
public object entityToCheck;
105143
public bool entityWasDeemedDirty = false;
106144

107-
public override bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types)
145+
public override bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, IType[] types)
108146
{
109147
if (entity == entityToCheck) { entityWasDeemedDirty = true; }
110148

src/NHibernate/Mapping/ByCode/Conformist/ComponentMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace NHibernate.Mapping.ByCode.Conformist
55
{
6-
public class ComponentMapping<T> : ComponentCustomizer<T> where T : class
6+
public class ComponentMapping<T> : ComponentCustomizer<T>
77
{
88
public ComponentMapping() : base(new ExplicitDeclarationsHolder(), new CustomizersHolder()) { }
99
}

src/NHibernate/Mapping/ByCode/IBagPropertiesMapper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ namespace NHibernate.Mapping.ByCode
22
{
33
public interface IBagPropertiesMapper : ICollectionPropertiesMapper {}
44

5-
public interface IBagPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement> where TEntity : class {}
5+
public interface IBagPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement>
6+
{}
67
}

src/NHibernate/Mapping/ByCode/IClassMapper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public interface IClassAttributesMapper<TEntity> : IEntityAttributesMapper, IEnt
4747
void Id<TProperty>(Expression<Func<TEntity, TProperty>> idProperty, Action<IIdMapper> idMapper);
4848
void Id(string notVisiblePropertyOrFieldName, Action<IIdMapper> idMapper);
4949

50-
void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty) where TComponent : class;
51-
void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty, Action<IComponentAsIdMapper<TComponent>> idMapper) where TComponent : class;
52-
void ComponentAsId<TComponent>(string notVisiblePropertyOrFieldName) where TComponent : class;
53-
void ComponentAsId<TComponent>(string notVisiblePropertyOrFieldName, Action<IComponentAsIdMapper<TComponent>> idMapper) where TComponent : class;
50+
void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty);
51+
void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty, Action<IComponentAsIdMapper<TComponent>> idMapper);
52+
void ComponentAsId<TComponent>(string notVisiblePropertyOrFieldName);
53+
void ComponentAsId<TComponent>(string notVisiblePropertyOrFieldName, Action<IComponentAsIdMapper<TComponent>> idMapper);
5454

5555
void ComposedId(Action<IComposedIdMapper<TEntity>> idPropertiesMapping);
5656

src/NHibernate/Mapping/ByCode/ICollectionPropertiesMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public interface ICollectionPropertiesMapper : IEntityPropertyMapper, ICollectio
3131
void Persister(System.Type persister);
3232
}
3333

34-
public interface ICollectionPropertiesMapper<TEntity, TElement> : IEntityPropertyMapper, ICollectionSqlsMapper where TEntity : class
34+
public interface ICollectionPropertiesMapper<TEntity, TElement> : IEntityPropertyMapper, ICollectionSqlsMapper
3535
{
3636
void Inverse(bool value);
3737
void Mutable(bool value);

src/NHibernate/Mapping/ByCode/IComponentMapper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ public interface IComponentAttributesMapper<TComponent> : IEntityPropertyMapper
2828
void Class<TConcrete>() where TConcrete : TComponent;
2929
}
3030

31-
public interface IComponentMapper<TComponent> : IComponentAttributesMapper<TComponent>, IPropertyContainerMapper<TComponent> where TComponent : class {}
31+
public interface IComponentMapper<TComponent> : IComponentAttributesMapper<TComponent>, IPropertyContainerMapper<TComponent>
32+
{}
3233
}

src/NHibernate/Mapping/ByCode/IDynamicComponentAttributesMapper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public interface IDynamicComponentAttributesMapper<TComponent> : IEntityProperty
1616
void Unique(bool unique);
1717
}
1818

19-
public interface IDynamicComponentMapper<TComponent> : IDynamicComponentAttributesMapper<TComponent>, IPropertyContainerMapper<TComponent> where TComponent : class { }
19+
public interface IDynamicComponentMapper<TComponent> : IDynamicComponentAttributesMapper<TComponent>, IPropertyContainerMapper<TComponent>
20+
{ }
2021

2122
}

src/NHibernate/Mapping/ByCode/IIdBagPropertiesMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public interface IIdBagPropertiesMapper : ICollectionPropertiesMapper
66
void Id(Action<ICollectionIdMapper> idMapping);
77
}
88

9-
public interface IIdBagPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement> where TEntity : class
9+
public interface IIdBagPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement>
1010
{
1111
void Id(Action<ICollectionIdMapper> idMapping);
1212
}

src/NHibernate/Mapping/ByCode/IKeyMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public interface IKeyMapper : IColumnsMapper
2929
void ForeignKey(string foreignKeyName);
3030
}
3131

32-
public interface IKeyMapper<TEntity> : IColumnsMapper where TEntity : class
32+
public interface IKeyMapper<TEntity> : IColumnsMapper
3333
{
3434
void OnDelete(OnDeleteAction deleteAction);
3535
void PropertyRef<TProperty>(Expression<Func<TEntity, TProperty>> propertyGetter);

src/NHibernate/Mapping/ByCode/IListPropertiesMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public interface IListPropertiesMapper : ICollectionPropertiesMapper
77
void Index(Action<IListIndexMapper> listIndexMapping);
88
}
99

10-
public interface IListPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement> where TEntity : class
10+
public interface IListPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement>
1111
{
1212
void Index(Action<IListIndexMapper> listIndexMapping);
1313
}

0 commit comments

Comments
 (0)