Skip to content

Commit 0c76901

Browse files
committed
Merge branch 'expose_entity_type' of https://github.com/icambron/fluent-nhibernate into icambron-expose_entity_type
Conflicts: src/FluentNHibernate/Mapping/ManyToManyPart.cs src/FluentNHibernate/Mapping/ToManyBase.cs
2 parents 9375fef + 9ab7678 commit 0c76901

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/FluentNHibernate/Mapping/ManyToManyPart.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace FluentNHibernate.Mapping
99
public class ManyToManyPart<TChild> : ToManyBase<ManyToManyPart<TChild>, TChild, ManyToManyMapping>
1010
{
1111
private readonly IList<FilterPart> childFilters = new List<FilterPart>();
12-
private readonly Type entity;
1312
private readonly FetchTypeExpression<ManyToManyPart<TChild>> fetch;
1413
private readonly NotFoundExpression<ManyToManyPart<TChild>> notFound;
1514
private IndexManyToManyPart manyToManyIndex;
@@ -23,13 +22,11 @@ public class ManyToManyPart<TChild> : ToManyBase<ManyToManyPart<TChild>, TChild,
2322
public ManyToManyPart(Type entity, Member property)
2423
: this(entity, property, property.PropertyType)
2524
{
26-
childType = property.PropertyType;
2725
}
2826

2927
protected ManyToManyPart(Type entity, Member member, Type collectionType)
3028
: base(entity, member, collectionType)
3129
{
32-
this.entity = entity;
3330
childType = collectionType;
3431

3532
fetch = new FetchTypeExpression<ManyToManyPart<TChild>>(this, value => collectionAttributes.Set(x => x.Fetch, value));
@@ -220,8 +217,7 @@ protected override ICollectionRelationshipMapping GetRelationship()
220217
{
221218
var mapping = new ManyToManyMapping(relationshipAttributes.CloneInner())
222219
{
223-
ContainingEntityType = entity,
224-
220+
ContainingEntityType = EntityType,
225221
};
226222

227223
if (isTernary && valueType != null)
@@ -336,7 +332,7 @@ protected override CollectionMapping GetCollectionMapping()
336332

337333
// key columns
338334
if (parentKeyColumns.Count == 0)
339-
collection.Key.AddDefaultColumn(new ColumnMapping { Name = entity.Name + "_id" });
335+
collection.Key.AddDefaultColumn(new ColumnMapping { Name = EntityType.Name + "_id" });
340336

341337
foreach (var column in parentKeyColumns)
342338
collection.Key.AddColumn(column);

src/FluentNHibernate/Mapping/ToManyBase.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public abstract class ToManyBase<T, TChild, TRelationshipAttributes> : ICollecti
2828
private Func<AttributeStore, CollectionMapping> collectionBuilder;
2929
private IndexMapping indexMapping;
3030
protected Member member;
31-
private Type entity;
31+
private readonly Type entity;
3232

3333
protected ToManyBase(Type entity, Member member, Type type)
3434
{
@@ -48,6 +48,15 @@ protected ToManyBase(Type entity, Member member, Type type)
4848
relationshipAttributes.SetDefault(x => x.Class, new TypeReference(typeof(TChild)));
4949
}
5050

51+
/// <summary>
52+
/// Return the type of the owning entity
53+
/// </summary>
54+
/// <returns>Type</returns>
55+
public Type EntityType
56+
{
57+
get { return entity; }
58+
}
59+
5160
/// <summary>
5261
/// This method is used to set a different key column in this table to be used for joins.
5362
/// The output is set as the property-ref attribute in the "key" subelement of the collection

0 commit comments

Comments
 (0)