Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Applied fluent_nh.patch from Ayende.
1) it automatically detect if we should use <set> or <bag> 2) it now recognize <many-to-many> associations. git-svn-id: https://fluent-nhibernate.googlecode.com/svn/trunk@144 48f0ce17-cc52-0410-af8c-857c09b6549b
- Loading branch information
Showing
11 changed files
with
128 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Iesi.Collections.Generic; | ||
|
||
namespace FluentNHibernate.Testing.AutoMap | ||
{ | ||
namespace ManyToMany | ||
{ | ||
public class ManyToMany1 | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual ISet<ManyToMany2> Many1 { get; set; } | ||
} | ||
|
||
public class ManyToMany2 | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual ISet<ManyToMany1> Many2 { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
using FluentNHibernate.Mapping; | ||
|
||
namespace FluentNHibernate.AutoMap | ||
{ | ||
public class ManyToManyAutoMapper : IAutoMapper | ||
{ | ||
public bool MapsProperty(PropertyInfo property) | ||
{ | ||
var type = property.PropertyType; | ||
if (type.Namespace != "Iesi.Collections.Generic" && | ||
type.Namespace != "System.Collections.Generic") | ||
return false; | ||
|
||
var inverseSide = type.GetGenericTypeDefinition() | ||
.MakeGenericType(property.DeclaringType); | ||
|
||
var argument = type.GetGenericArguments()[0]; | ||
var hasInverse = argument.GetProperties() | ||
.Where(x => x.PropertyType == inverseSide) | ||
.Count() > 0; | ||
return hasInverse; | ||
} | ||
|
||
public void Map<T>(AutoMap<T> classMap, PropertyInfo property) | ||
{ | ||
var classMapType = typeof(ClassMap<T>); | ||
var hasManyMethod = classMapType.GetMethod("HasManyToMany"); | ||
var listType = property.PropertyType.GetGenericArguments()[0]; | ||
var genericHasManyMethod = hasManyMethod.MakeGenericMethod(listType); | ||
genericHasManyMethod.Invoke(classMap, new object[] { ExpressionBuilder.Create<T>(property) }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters