You can specify the type of the entities in the collection in ManyToMany:
mapping.ManyToMany(p => { p.Class(classType); p.Column(...); }):
RP
On Sunday, November 23, 2014 8:09:36 AM UTC, Denis Pujdak wrote:
>
> I use NHibernate 4.0.2.4000. I'm creating a mapping using PropertyInfo:
>
> PropertyInfo[] props = classType.GetProperties();
> foreach (PropertyInfo prop in props)
> {
> /* some code */
>
> Bag(prop.Name, collectionMapping =>
> {
> collectionMapping.Table(prop.Name + "_" + classType.Name +"_Rel");
> collectionMapping.Key(k => k.Column(prop.Name + "_Id"));
> },
> mapping => mapping.ManyToMany(p => p.Column(classType.Name + "_Id")));
>
> /* some code */
> }
>
>
> But the "Bag" returns an error: *The type arguments for method [...]
> cannot be inferred from the usage. Try specifying the type arguments
> explicitly*. I know that I have to use Bag<TElement>() but I don't have
> TElement.
>
> Methods (Id(), Property()) work well. The method ManyToOne() is in the
> same situation.
>
> I tried to use it:
>
> this.GetType()
> .GetMethod("Bag")
> .MakeGenericMethod(prop.PropertyType)
> .Invoke(this, new object[]{ prop.Name, [...], [...] });
>
>
> but delegates are too complicated.
>
> Maybe someone knows another solution? Please don't propose to do map in
> the xml in memory dynamically. Thanks.
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.