MakoLab / RomanticWeb

RDF-Object Mapping for the Semantic Web
http://romanticweb.net/
Other
12 stars 9 forks source link

Collection mapping from concrete base class #53

Closed tpluscode closed 10 years ago

tpluscode commented 10 years ago

Fluent mappings can be created to map concrete classes.

It has been discovered that mapping type nested inside the mapped class doesn't work if the type is generic. Here's an example:

public class Base<T>
{
   public int InBaseClass { get; set; }

   public class BaseMap : EntityMap<Base<T>>
   {
       public BaseMap()
       {
           Property(e => e.InBaseClass).Term.Is("ex", "inBaseClass");
        }
    }
}
tpluscode commented 10 years ago

The problem is that a type nested inside a generic type cannot be instantiated. That's also true if otherwise the type would have been constructable. The solution is to map the base type and move the map class to outer scope

public class Base<T> : IBase
{
   public int InBaseClass { get; set; }
}

public class BaseMap : EntityMap<IBase>
{
    public BaseMap()
    {
        Property(e => e.InBaseClass).Term.Is("ex", "inBaseClass");
    }
}