|
From: <fab...@us...> - 2011-04-29 21:16:29
|
Revision: 5790
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5790&view=rev
Author: fabiomaulo
Date: 2011-04-29 21:16:22 +0000 (Fri, 29 Apr 2011)
Log Message:
-----------
Customizers with mapping of not visible members
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPlainPropertyContainerMapper.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPropertyContainerMapper.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/AllPropertiesRegistrationTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPlainPropertyContainerMapper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPlainPropertyContainerMapper.cs 2011-04-29 18:28:17 UTC (rev 5789)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPlainPropertyContainerMapper.cs 2011-04-29 21:16:22 UTC (rev 5790)
@@ -32,6 +32,7 @@
void ManyToOne<TProperty>(Expression<Func<TContainer, TProperty>> property, Action<IManyToOneMapper> mapping) where TProperty : class;
void ManyToOne<TProperty>(Expression<Func<TContainer, TProperty>> property) where TProperty : class;
+ void ManyToOne<TProperty>(string notVidiblePropertyOrFieldName, Action<IManyToOneMapper> mapping) where TProperty : class;
}
public interface IBasePlainPropertyContainerMapper<TContainer> : IMinimalPlainPropertyContainerMapper<TContainer>
@@ -39,16 +40,24 @@
void Component<TComponent>(Expression<Func<TContainer, TComponent>> property,
Action<IComponentMapper<TComponent>> mapping) where TComponent : class;
void Component<TComponent>(Expression<Func<TContainer, TComponent>> property) where TComponent : class;
-
void Component<TComponent>(Expression<Func<TContainer, IDictionary>> property,
TComponent dynamicComponentTemplate,
Action<IDynamicComponentMapper<TComponent>> mapping) where TComponent : class;
+ void Component<TComponent>(string notVidiblePropertyOrFieldName,
+ Action<IComponentMapper<TComponent>> mapping) where TComponent : class;
+ void Component<TComponent>(string notVidiblePropertyOrFieldName) where TComponent : class;
+ void Component<TComponent>(string notVidiblePropertyOrFieldName,
+ TComponent dynamicComponentTemplate,
+ Action<IDynamicComponentMapper<TComponent>> mapping) where TComponent : class;
+
void Any<TProperty>(Expression<Func<TContainer, TProperty>> property, System.Type idTypeOfMetaType, Action<IAnyMapper> mapping) where TProperty : class;
+ void Any<TProperty>(string notVidiblePropertyOrFieldName, System.Type idTypeOfMetaType, Action<IAnyMapper> mapping) where TProperty : class;
}
public interface IPlainPropertyContainerMapper<TContainer> : IBasePlainPropertyContainerMapper<TContainer>
{
void OneToOne<TProperty>(Expression<Func<TContainer, TProperty>> property, Action<IOneToOneMapper> mapping) where TProperty : class;
+ void OneToOne<TProperty>(string notVidiblePropertyOrFieldName, Action<IOneToOneMapper> mapping) where TProperty : class;
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPropertyContainerMapper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPropertyContainerMapper.cs 2011-04-29 18:28:17 UTC (rev 5789)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPropertyContainerMapper.cs 2011-04-29 21:16:22 UTC (rev 5790)
@@ -33,35 +33,63 @@
Action<ICollectionElementRelation<TElement>> mapping);
void Set<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property,
Action<ISetPropertiesMapper<TEntity, TElement>> collectionMapping);
+ void Set<TElement>(string notVidiblePropertyOrFieldName,
+ Action<ISetPropertiesMapper<TEntity, TElement>> collectionMapping,
+ Action<ICollectionElementRelation<TElement>> mapping);
+ void Set<TElement>(string notVidiblePropertyOrFieldName,
+ Action<ISetPropertiesMapper<TEntity, TElement>> collectionMapping);
void Bag<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property,
Action<IBagPropertiesMapper<TEntity, TElement>> collectionMapping,
Action<ICollectionElementRelation<TElement>> mapping);
void Bag<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property,
Action<IBagPropertiesMapper<TEntity, TElement>> collectionMapping);
+ void Bag<TElement>(string notVidiblePropertyOrFieldName,
+ Action<IBagPropertiesMapper<TEntity, TElement>> collectionMapping,
+ Action<ICollectionElementRelation<TElement>> mapping);
+ void Bag<TElement>(string notVidiblePropertyOrFieldName,
+ Action<IBagPropertiesMapper<TEntity, TElement>> collectionMapping);
void List<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property,
Action<IListPropertiesMapper<TEntity, TElement>> collectionMapping,
Action<ICollectionElementRelation<TElement>> mapping);
void List<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property,
Action<IListPropertiesMapper<TEntity, TElement>> collectionMapping);
+ void List<TElement>(string notVidiblePropertyOrFieldName,
+ Action<IListPropertiesMapper<TEntity, TElement>> collectionMapping,
+ Action<ICollectionElementRelation<TElement>> mapping);
+ void List<TElement>(string notVidiblePropertyOrFieldName,
+ Action<IListPropertiesMapper<TEntity, TElement>> collectionMapping);
void Map<TKey, TElement>(Expression<Func<TEntity, IDictionary<TKey, TElement>>> property,
Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping,
Action<IMapKeyRelation<TKey>> keyMapping,
Action<ICollectionElementRelation<TElement>> mapping);
-
void Map<TKey, TElement>(Expression<Func<TEntity, IDictionary<TKey, TElement>>> property,
Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping,
Action<ICollectionElementRelation<TElement>> mapping);
void Map<TKey, TElement>(Expression<Func<TEntity, IDictionary<TKey, TElement>>> property,
Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping);
+ void Map<TKey, TElement>(string notVidiblePropertyOrFieldName,
+ Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping,
+ Action<IMapKeyRelation<TKey>> keyMapping,
+ Action<ICollectionElementRelation<TElement>> mapping);
+ void Map<TKey, TElement>(string notVidiblePropertyOrFieldName,
+ Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping,
+ Action<ICollectionElementRelation<TElement>> mapping);
+ void Map<TKey, TElement>(string notVidiblePropertyOrFieldName,
+ Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping);
void IdBag<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property,
Action<IIdBagPropertiesMapper<TEntity, TElement>> collectionMapping,
Action<ICollectionElementRelation<TElement>> mapping);
void IdBag<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property,
Action<IIdBagPropertiesMapper<TEntity, TElement>> collectionMapping);
+ void IdBag<TElement>(string notVidiblePropertyOrFieldName,
+ Action<IIdBagPropertiesMapper<TEntity, TElement>> collectionMapping,
+ Action<ICollectionElementRelation<TElement>> mapping);
+ void IdBag<TElement>(string notVidiblePropertyOrFieldName,
+ Action<IIdBagPropertiesMapper<TEntity, TElement>> collectionMapping);
}
public interface IPropertyContainerMapper<TEntity> : ICollectionPropertiesContainerMapper<TEntity>, IPlainPropertyContainerMapper<TEntity> where TEntity : class {}
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs 2011-04-29 18:28:17 UTC (rev 5789)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs 2011-04-29 21:16:22 UTC (rev 5790)
@@ -43,10 +43,7 @@
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
MemberInfo memberOf = TypeExtensions.DecodeMemberAccessExpressionOf(property);
- CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, member), mapping);
- CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, memberOf), mapping);
- explicitDeclarationsHolder.AddAsProperty(member);
- explicitDeclarationsHolder.AddAsProperty(memberOf);
+ RegistePropertyMapping(mapping, member, memberOf);
}
public void Property(string notVidiblePropertyOrFieldName, Action<IPropertyMapper> mapping)
@@ -60,12 +57,18 @@
// done unsing expressions are faster than those done with pure reflection.
MemberInfo member = typeof(TEntity).GetPropertyOrFieldMatchingName(notVidiblePropertyOrFieldName);
MemberInfo memberOf = member.GetMemberFromReflectedType(typeof(TEntity));
- CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, member), mapping);
- CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, memberOf), mapping);
- explicitDeclarationsHolder.AddAsProperty(member);
- explicitDeclarationsHolder.AddAsProperty(memberOf);
+ RegistePropertyMapping(mapping, member, memberOf);
}
+ protected void RegistePropertyMapping(Action<IPropertyMapper> mapping, params MemberInfo[] members)
+ {
+ foreach (var member in members)
+ {
+ CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, member), mapping);
+ explicitDeclarationsHolder.AddAsProperty(member);
+ }
+ }
+
public void Component<TComponent>(Expression<Func<TEntity, TComponent>> property,
Action<IComponentMapper<TComponent>> mapping) where TComponent : class
{
@@ -80,11 +83,19 @@
where TComponent : class
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- mapping(new ComponentCustomizer<TComponent>(explicitDeclarationsHolder, CustomizersHolder, new PropertyPath(PropertyPath, member)));
MemberInfo memberOf = TypeExtensions.DecodeMemberAccessExpressionOf(property);
- mapping(new ComponentCustomizer<TComponent>(explicitDeclarationsHolder, CustomizersHolder, new PropertyPath(PropertyPath, memberOf)));
+ RegisterComponentMapping<TComponent>(mapping, member, memberOf);
}
+ protected void RegisterComponentMapping<TComponent>(Action<IComponentMapper<TComponent>> mapping, params MemberInfo[] members)
+ where TComponent : class
+ {
+ foreach (var member in members)
+ {
+ mapping(new ComponentCustomizer<TComponent>(explicitDeclarationsHolder, CustomizersHolder, new PropertyPath(PropertyPath, member)));
+ }
+ }
+
public void Component<TComponent>(Expression<Func<TEntity, IDictionary>> property,
TComponent dynamicComponentTemplate,
Action<IDynamicComponentMapper<TComponent>> mapping) where TComponent : class
@@ -95,11 +106,19 @@
protected virtual void RegisterDynamicComponentMapping<TComponent>(Expression<Func<TEntity, IDictionary>> property, Action<IDynamicComponentMapper<TComponent>> mapping) where TComponent : class
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- mapping(new DynamicComponentCustomizer<TComponent>(explicitDeclarationsHolder, CustomizersHolder, new PropertyPath(PropertyPath, member)));
MemberInfo memberOf = TypeExtensions.DecodeMemberAccessExpressionOf(property);
- mapping(new DynamicComponentCustomizer<TComponent>(explicitDeclarationsHolder, CustomizersHolder, new PropertyPath(PropertyPath, memberOf)));
+ RegisterDynamicComponentMapping<TComponent>(mapping, member, memberOf);
}
+ protected void RegisterDynamicComponentMapping<TComponent>(Action<IDynamicComponentMapper<TComponent>> mapping, params MemberInfo[] members)
+ where TComponent : class
+ {
+ foreach (var member in members)
+ {
+ mapping(new DynamicComponentCustomizer<TComponent>(explicitDeclarationsHolder, CustomizersHolder, new PropertyPath(PropertyPath, member)));
+ }
+ }
+
public void ManyToOne<TProperty>(Expression<Func<TEntity, TProperty>> property, Action<IManyToOneMapper> mapping)
where TProperty : class
{
@@ -110,13 +129,20 @@
where TProperty : class
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, member), mapping);
MemberInfo memberOf = TypeExtensions.DecodeMemberAccessExpressionOf(property);
- CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, memberOf), mapping);
- explicitDeclarationsHolder.AddAsManyToOneRelation(member);
- explicitDeclarationsHolder.AddAsManyToOneRelation(memberOf);
+ RegisterManyToOneMapping<TProperty>(mapping, member, memberOf);
}
+ protected void RegisterManyToOneMapping<TProperty>(Action<IManyToOneMapper> mapping, params MemberInfo[] members)
+ where TProperty : class
+ {
+ foreach (var member in members)
+ {
+ CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, member), mapping);
+ explicitDeclarationsHolder.AddAsManyToOneRelation(member);
+ }
+ }
+
public void ManyToOne<TProperty>(Expression<Func<TEntity, TProperty>> property) where TProperty : class
{
ManyToOne(property, x => { });
@@ -126,13 +152,20 @@
where TProperty : class
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, member), mapping);
MemberInfo memberOf = TypeExtensions.DecodeMemberAccessExpressionOf(property);
- CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, memberOf), mapping);
- explicitDeclarationsHolder.AddAsOneToOneRelation(member);
- explicitDeclarationsHolder.AddAsOneToOneRelation(memberOf);
+ RegisterOneToOneMapping<TProperty>(mapping, member, memberOf);
}
+ protected void RegisterOneToOneMapping<TProperty>(Action<IOneToOneMapper> mapping, params MemberInfo[] members)
+ where TProperty : class
+ {
+ foreach (var member in members)
+ {
+ CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, member), mapping);
+ explicitDeclarationsHolder.AddAsOneToOneRelation(member);
+ }
+ }
+
public void Any<TProperty>(Expression<Func<TEntity, TProperty>> property, System.Type idTypeOfMetaType, Action<IAnyMapper> mapping)
where TProperty : class
{
@@ -143,15 +176,22 @@
where TProperty : class
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, member), am => am.IdType(idTypeOfMetaType));
- CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, member), mapping);
MemberInfo memberOf = TypeExtensions.DecodeMemberAccessExpressionOf(property);
- CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, memberOf), mapping);
- CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, memberOf), am => am.IdType(idTypeOfMetaType));
- explicitDeclarationsHolder.AddAsAny(member);
- explicitDeclarationsHolder.AddAsAny(memberOf);
+ RegisterAnyMapping<TProperty>(mapping, idTypeOfMetaType, member, memberOf);
}
+ protected void RegisterAnyMapping<TProperty>(Action<IAnyMapper> mapping, System.Type idTypeOfMetaType, params MemberInfo[] members)
+ where TProperty : class
+ {
+ foreach (var member in members)
+ {
+ CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, member), am => am.IdType(idTypeOfMetaType));
+ CustomizersHolder.AddCustomizer(new PropertyPath(PropertyPath, member), mapping);
+
+ explicitDeclarationsHolder.AddAsAny(member);
+ }
+ }
+
public void Set<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property,
Action<ISetPropertiesMapper<TEntity, TElement>> collectionMapping,
Action<ICollectionElementRelation<TElement>> mapping)
@@ -168,14 +208,19 @@
protected virtual void RegisterSetMapping<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, Action<ISetPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- collectionMapping(new SetPropertiesCustomizer<TEntity, TElement>(explicitDeclarationsHolder, new PropertyPath(null, member), CustomizersHolder));
- mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, member), CustomizersHolder));
-
MemberInfo memberOf = TypeExtensions.DecodeMemberAccessExpressionOf(property);
- collectionMapping(new SetPropertiesCustomizer<TEntity, TElement>(explicitDeclarationsHolder, new PropertyPath(null, memberOf), CustomizersHolder));
- mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, member), CustomizersHolder));
+ RegisterSetMapping<TElement>(collectionMapping, mapping, member, memberOf);
}
+ protected void RegisterSetMapping<TElement>(Action<ISetPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping, params MemberInfo[] members)
+ {
+ foreach (var member in members)
+ {
+ collectionMapping(new SetPropertiesCustomizer<TEntity, TElement>(explicitDeclarationsHolder, new PropertyPath(null, member), CustomizersHolder));
+ mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, member), CustomizersHolder));
+ }
+ }
+
public void Bag<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property,
Action<IBagPropertiesMapper<TEntity, TElement>> collectionMapping,
Action<ICollectionElementRelation<TElement>> mapping)
@@ -191,14 +236,19 @@
protected virtual void RegisterBagMapping<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, Action<IBagPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- collectionMapping(new BagPropertiesCustomizer<TEntity, TElement>(explicitDeclarationsHolder, new PropertyPath(null, member), CustomizersHolder));
- mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, member), CustomizersHolder));
-
MemberInfo memberOf = TypeExtensions.DecodeMemberAccessExpressionOf(property);
- collectionMapping(new BagPropertiesCustomizer<TEntity, TElement>(explicitDeclarationsHolder, new PropertyPath(null, memberOf), CustomizersHolder));
- mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, memberOf), CustomizersHolder));
+ RegisterBagMapping<TElement>(collectionMapping, mapping, member, memberOf);
}
+ protected void RegisterBagMapping<TElement>(Action<IBagPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping, params MemberInfo[] members)
+ {
+ foreach (var member in members)
+ {
+ collectionMapping(new BagPropertiesCustomizer<TEntity, TElement>(explicitDeclarationsHolder, new PropertyPath(null, member), CustomizersHolder));
+ mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, member), CustomizersHolder));
+ }
+ }
+
public void List<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property,
Action<IListPropertiesMapper<TEntity, TElement>> collectionMapping,
Action<ICollectionElementRelation<TElement>> mapping)
@@ -214,14 +264,19 @@
protected virtual void RegisterListMapping<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, Action<IListPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- collectionMapping(new ListPropertiesCustomizer<TEntity, TElement>(explicitDeclarationsHolder, new PropertyPath(null, member), CustomizersHolder));
- mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, member), CustomizersHolder));
-
MemberInfo memberOf = TypeExtensions.DecodeMemberAccessExpressionOf(property);
- collectionMapping(new ListPropertiesCustomizer<TEntity, TElement>(explicitDeclarationsHolder, new PropertyPath(null, memberOf), CustomizersHolder));
- mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, member), CustomizersHolder));
+ RegisterListMapping<TElement>(collectionMapping, mapping, member, memberOf);
}
+ protected void RegisterListMapping<TElement>(Action<IListPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping, params MemberInfo[] members)
+ {
+ foreach (var member in members)
+ {
+ collectionMapping(new ListPropertiesCustomizer<TEntity, TElement>(explicitDeclarationsHolder, new PropertyPath(null, member), CustomizersHolder));
+ mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, member), CustomizersHolder));
+ }
+ }
+
public void Map<TKey, TElement>(Expression<Func<TEntity, IDictionary<TKey, TElement>>> property,
Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping,
Action<IMapKeyRelation<TKey>> keyMapping,
@@ -238,18 +293,21 @@
protected virtual void RegisterMapMapping<TKey, TElement>(Expression<Func<TEntity, IDictionary<TKey, TElement>>> property, Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping, Action<IMapKeyRelation<TKey>> keyMapping, Action<ICollectionElementRelation<TElement>> mapping)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- var memberPath = new PropertyPath(PropertyPath, member);
- collectionMapping(new MapPropertiesCustomizer<TEntity, TKey, TElement>(explicitDeclarationsHolder, memberPath, CustomizersHolder));
- keyMapping(new MapKeyRelationCustomizer<TKey>(explicitDeclarationsHolder, memberPath, CustomizersHolder));
- mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, memberPath, CustomizersHolder));
-
MemberInfo memberOf = TypeExtensions.DecodeMemberAccessExpressionOf(property);
- var memberOfPath = new PropertyPath(PropertyPath, memberOf);
- collectionMapping(new MapPropertiesCustomizer<TEntity, TKey, TElement>(explicitDeclarationsHolder, memberOfPath, CustomizersHolder));
- keyMapping(new MapKeyRelationCustomizer<TKey>(explicitDeclarationsHolder, memberOfPath, CustomizersHolder));
- mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, memberOfPath, CustomizersHolder));
+ RegisterMapMapping<TKey, TElement>(collectionMapping, keyMapping, mapping, member, memberOf);
}
+ protected virtual void RegisterMapMapping<TKey, TElement>(Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping, Action<IMapKeyRelation<TKey>> keyMapping, Action<ICollectionElementRelation<TElement>> mapping, params MemberInfo[] members)
+ {
+ foreach (var member in members)
+ {
+ var memberPath = new PropertyPath(PropertyPath, member);
+ collectionMapping(new MapPropertiesCustomizer<TEntity, TKey, TElement>(explicitDeclarationsHolder, memberPath, CustomizersHolder));
+ keyMapping(new MapKeyRelationCustomizer<TKey>(explicitDeclarationsHolder, memberPath, CustomizersHolder));
+ mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, memberPath, CustomizersHolder));
+ }
+ }
+
public void Map<TKey, TElement>(Expression<Func<TEntity, IDictionary<TKey, TElement>>> property,
Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping,
Action<ICollectionElementRelation<TElement>> mapping)
@@ -273,12 +331,122 @@
protected virtual void RegisterIdBagMapping<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, Action<IIdBagPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- collectionMapping(new IdBagPropertiesCustomizer<TEntity, TElement>(explicitDeclarationsHolder, new PropertyPath(null, member), CustomizersHolder));
- mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, member), CustomizersHolder));
-
MemberInfo memberOf = TypeExtensions.DecodeMemberAccessExpressionOf(property);
- collectionMapping(new IdBagPropertiesCustomizer<TEntity, TElement>(explicitDeclarationsHolder, new PropertyPath(null, memberOf), CustomizersHolder));
- mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, memberOf), CustomizersHolder));
+ RegisterIdBagMapping<TElement>(collectionMapping, mapping, member, memberOf);
}
+
+ protected virtual void RegisterIdBagMapping<TElement>(Action<IIdBagPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping,params MemberInfo[] members)
+ {
+ foreach (var member in members)
+ {
+ collectionMapping(new IdBagPropertiesCustomizer<TEntity, TElement>(explicitDeclarationsHolder, new PropertyPath(null, member), CustomizersHolder));
+ mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, member), CustomizersHolder));
+ }
+ }
+
+ public void Set<TElement>(string notVidiblePropertyOrFieldName, Action<ISetPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping)
+ {
+ MemberInfo member = typeof(TEntity).GetPropertyOrFieldMatchingName(notVidiblePropertyOrFieldName);
+ MemberInfo memberOf = member.GetMemberFromReflectedType(typeof(TEntity));
+ RegisterSetMapping<TElement>(collectionMapping, mapping, member, memberOf);
+ }
+
+ public void Set<TElement>(string notVidiblePropertyOrFieldName, Action<ISetPropertiesMapper<TEntity, TElement>> collectionMapping)
+ {
+ Set(notVidiblePropertyOrFieldName, collectionMapping, x => { });
+ }
+
+ public void Bag<TElement>(string notVidiblePropertyOrFieldName, Action<IBagPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping)
+ {
+ MemberInfo member = typeof(TEntity).GetPropertyOrFieldMatchingName(notVidiblePropertyOrFieldName);
+ MemberInfo memberOf = member.GetMemberFromReflectedType(typeof(TEntity));
+ RegisterBagMapping<TElement>(collectionMapping, mapping, member, memberOf);
+ }
+
+ public void Bag<TElement>(string notVidiblePropertyOrFieldName, Action<IBagPropertiesMapper<TEntity, TElement>> collectionMapping)
+ {
+ Bag(notVidiblePropertyOrFieldName, collectionMapping, x => { });
+ }
+
+ public void List<TElement>(string notVidiblePropertyOrFieldName, Action<IListPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping)
+ {
+ MemberInfo member = typeof(TEntity).GetPropertyOrFieldMatchingName(notVidiblePropertyOrFieldName);
+ MemberInfo memberOf = member.GetMemberFromReflectedType(typeof(TEntity));
+ RegisterListMapping<TElement>(collectionMapping, mapping, member, memberOf);
+ }
+
+ public void List<TElement>(string notVidiblePropertyOrFieldName, Action<IListPropertiesMapper<TEntity, TElement>> collectionMapping)
+ {
+ List(notVidiblePropertyOrFieldName, collectionMapping, x => { });
+ }
+
+ public void Map<TKey, TElement>(string notVidiblePropertyOrFieldName, Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping, Action<IMapKeyRelation<TKey>> keyMapping, Action<ICollectionElementRelation<TElement>> mapping)
+ {
+ MemberInfo member = typeof(TEntity).GetPropertyOrFieldMatchingName(notVidiblePropertyOrFieldName);
+ MemberInfo memberOf = member.GetMemberFromReflectedType(typeof(TEntity));
+ RegisterMapMapping<TKey, TElement>(collectionMapping, keyMapping, mapping, member, memberOf);
+ }
+
+ public void Map<TKey, TElement>(string notVidiblePropertyOrFieldName, Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping)
+ {
+ Map(notVidiblePropertyOrFieldName, collectionMapping, x => { }, mapping);
+ }
+
+ public void Map<TKey, TElement>(string notVidiblePropertyOrFieldName, Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping)
+ {
+ Map(notVidiblePropertyOrFieldName, collectionMapping, x => { }, y => { });
+ }
+
+ public void IdBag<TElement>(string notVidiblePropertyOrFieldName, Action<IIdBagPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping)
+ {
+ MemberInfo member = typeof(TEntity).GetPropertyOrFieldMatchingName(notVidiblePropertyOrFieldName);
+ MemberInfo memberOf = member.GetMemberFromReflectedType(typeof(TEntity));
+ RegisterIdBagMapping<TElement>(collectionMapping, mapping, member, memberOf);
+ }
+
+ public void IdBag<TElement>(string notVidiblePropertyOrFieldName, Action<IIdBagPropertiesMapper<TEntity, TElement>> collectionMapping)
+ {
+ IdBag(notVidiblePropertyOrFieldName, collectionMapping, x => { });
+ }
+
+ public void ManyToOne<TProperty>(string notVidiblePropertyOrFieldName, Action<IManyToOneMapper> mapping) where TProperty : class
+ {
+ MemberInfo member = typeof(TEntity).GetPropertyOrFieldMatchingName(notVidiblePropertyOrFieldName);
+ MemberInfo memberOf = member.GetMemberFromReflectedType(typeof(TEntity));
+ RegisterManyToOneMapping<TProperty>(mapping, member, memberOf);
+ }
+
+ public void Component<TComponent>(string notVidiblePropertyOrFieldName, Action<IComponentMapper<TComponent>> mapping) where TComponent : class
+ {
+ MemberInfo member = typeof(TEntity).GetPropertyOrFieldMatchingName(notVidiblePropertyOrFieldName);
+ MemberInfo memberOf = member.GetMemberFromReflectedType(typeof(TEntity));
+ RegisterComponentMapping<TComponent>(mapping, member, memberOf);
+ }
+
+ public void Component<TComponent>(string notVidiblePropertyOrFieldName) where TComponent : class
+ {
+ Component<TComponent>(notVidiblePropertyOrFieldName, x => { });
+ }
+
+ public void Component<TComponent>(string notVidiblePropertyOrFieldName, TComponent dynamicComponentTemplate, Action<IDynamicComponentMapper<TComponent>> mapping) where TComponent : class
+ {
+ MemberInfo member = typeof(TEntity).GetPropertyOrFieldMatchingName(notVidiblePropertyOrFieldName);
+ MemberInfo memberOf = member.GetMemberFromReflectedType(typeof(TEntity));
+ RegisterDynamicComponentMapping<TComponent>(mapping, member, memberOf);
+ }
+
+ public void Any<TProperty>(string notVidiblePropertyOrFieldName, System.Type idTypeOfMetaType, Action<IAnyMapper> mapping) where TProperty : class
+ {
+ MemberInfo member = typeof(TEntity).GetPropertyOrFieldMatchingName(notVidiblePropertyOrFieldName);
+ MemberInfo memberOf = member.GetMemberFromReflectedType(typeof(TEntity));
+ RegisterAnyMapping<TProperty>(mapping, idTypeOfMetaType, member, memberOf);
+ }
+
+ public void OneToOne<TProperty>(string notVidiblePropertyOrFieldName, Action<IOneToOneMapper> mapping) where TProperty : class
+ {
+ MemberInfo member = typeof(TEntity).GetPropertyOrFieldMatchingName(notVidiblePropertyOrFieldName);
+ MemberInfo memberOf = member.GetMemberFromReflectedType(typeof(TEntity));
+ RegisterOneToOneMapping<TProperty>(mapping, member, memberOf);
+ }
}
}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/AllPropertiesRegistrationTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/AllPropertiesRegistrationTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/AllPropertiesRegistrationTests.cs 2011-04-29 21:16:22 UTC (rev 5790)
@@ -0,0 +1,260 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using NHibernate.Cfg.MappingSchema;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.ExpliticMappingTests
+{
+ public class AllPropertiesRegistrationTests
+ {
+ private class MyClass
+ {
+ public int Id { get; set; }
+ private int simple;
+ public int Simple
+ {
+ get { return simple; }
+ set { simple = value; }
+ }
+
+ private IList<string> complexType;
+ public IList<string> ComplexType
+ {
+ get { return complexType; }
+ set { complexType = value; }
+ }
+
+ private IEnumerable<string> bag;
+ public IEnumerable<string> Bag
+ {
+ get { return bag; }
+ set { bag = value; }
+ }
+
+ private IEnumerable<MyCompo> idBag;
+ public IEnumerable<MyCompo> IdBag
+ {
+ get { return idBag; }
+ set { idBag = value; }
+ }
+
+ private IEnumerable<string> set;
+ public IEnumerable<string> Set
+ {
+ get { return set; }
+ set { set = value; }
+ }
+
+ private IEnumerable<string> list;
+ public IEnumerable<string> List
+ {
+ get { return list; }
+ set { list = value; }
+ }
+
+ private IDictionary<int, string> map;
+ public IDictionary<int, string> Map
+ {
+ get { return map; }
+ set { map = value; }
+ }
+
+ private MyCompo compo;
+ public MyCompo Compo
+ {
+ get { return compo; }
+ set { compo = value; }
+ }
+
+ private Related oneToOne;
+ public Related OneToOne
+ {
+ get { return oneToOne; }
+ set { oneToOne = value; }
+ }
+
+ private Related manyToOne;
+ public Related ManyToOne
+ {
+ get { return manyToOne; }
+ set { manyToOne = value; }
+ }
+
+ private object any;
+ public object Any
+ {
+ get { return any; }
+ set { any = value; }
+ }
+
+ private IDictionary dynamicCompo;
+ public IDictionary DynamicCompo
+ {
+ get { return dynamicCompo; }
+ set { dynamicCompo = value; }
+ }
+ }
+
+ private class MyCompo
+ {
+ public int Something { get; set; }
+ }
+ private class Related
+ {
+ public int Id { get; set; }
+ }
+
+ private class Inherited:MyClass
+ {
+
+ }
+
+ [Test]
+ public void WhenMapPropertiesInTheInheritedThenMapInBase()
+ {
+ // without ignoring MyClass as root-class I will try to map all properties using the inherited class.
+ // NH have to recognize the case and, following Object-Relational-Mapping rules, map those properties in the base class.
+ // Where needed, using the SimpleModelInspector, the user can revert this behavior checking the DeclaringType and ReflectedType of the persistent member.
+ var mapper = new ModelMapper();
+ mapper.Class<MyClass>(mc => mc.Id(x => x.Id));
+ mapper.JoinedSubclass<Inherited>(mc =>
+ {
+ mc.Property(x => x.Simple, map => map.Access(Accessor.Field));
+ mc.Property(x => x.ComplexType, map => map.Access(Accessor.Field));
+ mc.Bag(x => x.Bag, y => y.Access(Accessor.Field));
+ mc.IdBag(x => x.IdBag, y => y.Access(Accessor.Field));
+ mc.List(x => x.List, y => y.Access(Accessor.Field));
+ mc.Set(x => x.Set, y => y.Access(Accessor.Field));
+ mc.Map(x => x.Map, y => y.Access(Accessor.Field));
+ mc.OneToOne(x => x.OneToOne, y => y.Access(Accessor.Field));
+ mc.ManyToOne(x => x.ManyToOne, y => y.Access(Accessor.Field));
+ mc.Any(x => x.Any, typeof(int), y => y.Access(Accessor.Field));
+ mc.Component(x => x.DynamicCompo, new { A=2 }, y => y.Access(Accessor.Field));
+ mc.Component(x => x.Compo, y =>
+ {
+ y.Access(Accessor.Field);
+ y.Property(c => c.Something);
+ });
+ });
+ var mappings = mapper.CompileMappingForAllExplicitAddedEntities();
+ var hbmClass = mappings.RootClasses[0];
+ var hbmJoinedSubclass = mappings.JoinedSubclasses[0];
+ hbmClass.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any", "DynamicCompo");
+ hbmClass.Properties.Select(p => p.Access).All(x=> x.Satisfy(access=> access.Contains("field.")));
+ hbmJoinedSubclass.Properties.Should().Be.Empty();
+ }
+
+ [Test]
+ public void WhenMapPropertiesInTheBaseJumpedClassThenMapInInherited()
+ {
+ // ignoring MyClass and using Inherited, as root-class, I will try to map all properties using the base class.
+ // NH have to recognize the case and map those properties in the inherited.
+ var inspector = new SimpleModelInspector();
+ inspector.IsRootEntity((type, declared) => type == typeof(Inherited));
+ var mapper = new ModelMapper();
+ mapper.Class<MyClass>(mc =>
+ {
+ mc.Id(x => x.Id);
+ mc.Property(x => x.Simple, map => map.Access(Accessor.Field));
+ mc.Property(x => x.ComplexType, map => map.Access(Accessor.Field));
+ mc.Bag(x => x.Bag, y => y.Access(Accessor.Field));
+ mc.IdBag(x => x.IdBag, y => y.Access(Accessor.Field));
+ mc.List(x => x.List, y => y.Access(Accessor.Field));
+ mc.Set(x => x.Set, y => y.Access(Accessor.Field));
+ mc.Map(x => x.Map, y => y.Access(Accessor.Field));
+ mc.OneToOne(x => x.OneToOne, y => y.Access(Accessor.Field));
+ mc.ManyToOne(x => x.ManyToOne, y => y.Access(Accessor.Field));
+ mc.Any(x => x.Any, typeof(int), y => y.Access(Accessor.Field));
+ mc.Component(x => x.DynamicCompo, new { A = 2 }, y => y.Access(Accessor.Field));
+ mc.Component(x => x.Compo, y =>
+ {
+ y.Access(Accessor.Field);
+ y.Property(c => c.Something);
+ });
+ });
+ mapper.Class<Inherited>(mc =>{});
+
+ var mappings = mapper.CompileMappingForAllExplicitAddedEntities();
+ var hbmClass = mappings.RootClasses[0];
+ mappings.JoinedSubclasses.Should().Be.Empty();
+ hbmClass.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any", "DynamicCompo");
+ hbmClass.Properties.Select(p => p.Access).All(x => x.Satisfy(access => access.Contains("field.")));
+ }
+
+ [Test]
+ public void WhenMapPropertiesInTheInheritedUsingMemberNameThenMapInBase()
+ {
+ // without ignoring MyClass as root-class I will try to map all properties using the inherited class.
+ // NH have to recognize the case and, following Object-Relational-Mapping rules, map those properties in the base class.
+ var mapper = new ModelMapper();
+ mapper.Class<MyClass>(mc => mc.Id(x => x.Id));
+ mapper.JoinedSubclass<Inherited>(mc =>
+ {
+ mc.Property("Simple", map => map.Access(Accessor.Field));
+ mc.Property("ComplexType", map => map.Access(Accessor.Field));
+ mc.Bag<string>("Bag", y => y.Access(Accessor.Field));
+ mc.IdBag<MyCompo>("IdBag", y => y.Access(Accessor.Field));
+ mc.List<string>("List", y => y.Access(Accessor.Field));
+ mc.Set<string>("Set", y => y.Access(Accessor.Field));
+ mc.Map<int, string>("Map", y => y.Access(Accessor.Field));
+ mc.OneToOne<Related>("OneToOne", y => y.Access(Accessor.Field));
+ mc.ManyToOne<Related>("ManyToOne", y => y.Access(Accessor.Field));
+ mc.Any<object>("Any", typeof(int), y => y.Access(Accessor.Field));
+ mc.Component("DynamicCompo", new { A = 2 }, y => y.Access(Accessor.Field));
+ mc.Component<MyCompo>("Compo", y =>
+ {
+ y.Access(Accessor.Field);
+ y.Property(c => c.Something);
+ });
+ });
+ var mappings = mapper.CompileMappingForAllExplicitAddedEntities();
+ var hbmClass = mappings.RootClasses[0];
+ var hbmJoinedSubclass = mappings.JoinedSubclasses[0];
+ hbmClass.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any", "DynamicCompo");
+ hbmClass.Properties.Select(p => p.Access).All(x => x.Satisfy(access => access.Contains("field.")));
+ hbmJoinedSubclass.Properties.Should().Be.Empty();
+ }
+
+ [Test]
+ public void WhenMapPropertiesInTheBaseJumpedClassUsingMemberNameThenMapInInherited()
+ {
+ // ignoring MyClass and using Inherited, as root-class, I will try to map all properties using the base class.
+ // NH have to recognize the case and map those properties in the inherited.
+ var inspector = new SimpleModelInspector();
+ inspector.IsRootEntity((type, declared) => type == typeof (Inherited));
+ var mapper = new ModelMapper();
+ mapper.Class<MyClass>(mc =>
+ {
+ mc.Id(x => x.Id);
+ mc.Property("Simple", map => map.Access(Accessor.Field));
+ mc.Property("ComplexType", map => map.Access(Accessor.Field));
+ mc.Bag<string>("Bag", y => y.Access(Accessor.Field));
+ mc.IdBag<MyCompo>("IdBag", y => y.Access(Accessor.Field));
+ mc.List<string>("List", y => y.Access(Accessor.Field));
+ mc.Set<string>("Set", y => y.Access(Accessor.Field));
+ mc.Map<int, string>("Map", y => y.Access(Accessor.Field));
+ mc.OneToOne<Related>("OneToOne", y => y.Access(Accessor.Field));
+ mc.ManyToOne<Related>("ManyToOne", y => y.Access(Accessor.Field));
+ mc.Any<object>("Any", typeof (int), y => y.Access(Accessor.Field));
+ mc.Component("DynamicCompo", new {A = 2}, y => y.Access(Accessor.Field));
+ mc.Component<MyCompo>("Compo", y =>
+ {
+ y.Access(Accessor.Field);
+ y.Property(c => c.Something);
+ });
+ });
+ mapper.Class<Inherited>(mc => { });
+
+ HbmMapping mappings = mapper.CompileMappingForAllExplicitAddedEntities();
+ HbmClass hbmClass = mappings.RootClasses[0];
+ mappings.JoinedSubclasses.Should().Be.Empty();
+ hbmClass.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any",
+ "DynamicCompo");
+ hbmClass.Properties.Select(p => p.Access).All(x => x.Satisfy(access => access.Contains("field.")));
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-29 18:28:17 UTC (rev 5789)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-29 21:16:22 UTC (rev 5790)
@@ -517,6 +517,7 @@
<Compile Include="MappingByCode\ConventionModelMapperTests\PropertyToFieldAccessorTest.cs" />
<Compile Include="MappingByCode\ConventionModelMapperTests\SafePoidTests.cs" />
<Compile Include="MappingByCode\ConventionModelMapperTests\VersionOnBaseClassIntegrationTest.cs" />
+ <Compile Include="MappingByCode\ExpliticMappingTests\AllPropertiesRegistrationTests.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\BagOfNestedComponentsWithParentTest.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ClassWithComponentsTest.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ComponentAsIdTests.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|