views:

234

answers:

1

I have a simple class that looks like this:

public class Item {
 // some properties
public virtual IDictionary<string, Detail> Details { get; private set; }
}

and then I have a map that looks like this:

map.HasMany(x => x.Details).AsMap<string>("Name").AsIndexedCollection<string>("Name", c => c.GetIndexMapping()).Cascade.All().KeyColumn("Item_Id"))

with this map I get the following error and I don't know how to solve it?

The type or method has 2 generic parameter(s), but 1 generic argument(s) were provided. A generic argument must be provided for each generic parameter.

A: 

I found a workaround for this. Basically I'm preventing the automapper from attempting to map an IDictionary. It forces me to have to map it manually in an override but at least it works.

I'm using an AutomappingConfiguration derived from DefaultAutomappingConfiguration.

public override bool ShouldMap(Member member)
{
    if ( member.PropertyType.IsGenericType )
    {
        if (member.PropertyType.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IDictionary<,>))
                    return false;
    }

    return base.ShouldMap(member);
}

And here's a couple of sample classes and the associated mapping that I'm using to make this happen:

public class ComponentA
{
    public virtual string Name { get; set; }
}

public class EntityF : Entity
{
    private IDictionary<string, ComponentA> _components = new Dictionary<string, ComponentA>();
    public IDictionary<string, ComponentA> Components
    {
        get { return _components; }
        set { _components = value; }
    }
}

public class EntityFMap : IAutoMappingOverride<EntityF>
{
    public void Override(AutoMapping<EntityF> mapping)
    {
        mapping.HasMany<ComponentA>(x => x.Components)
            .AsMap<string>("IndexKey")
            .KeyColumn("EntityF_Id")
            .Table("EntityF_Components")
            .Component(x =>
                           {
                               x.Map(c => c.Name);
                           })
            .Cascade.AllDeleteOrphan();
    }
}

I've just spent several hours to make this work, so I hope this saves someone else an evening of hair-pulling.

Chris Stavropoulos