Fluent NHibernate: subclasses within subclasses

I have different products. AppProduct now has different types of values ​​- value multiplication, list of values, etc.

   public class Product : Entity
   {
   }
   public class Quantity: Entity
   {
   }
   public class ListQuantity : Quantity
   {
      public virtual IList<int> Quantities { get; set; }
   }
   public class MultiplierQuantity : Quantity
   {
      public virtual int Multiplier { get; set; }
   }
   public class AppProduct : Product
   {
      public virtual Quantity Quantity { get; set; }
   }

      

The question is, is it possible to compare FNH or NH at all? In particular, with automatic display. It would be natural for me to display products in their own tables, but quantities would be part of the AppProducts ... table that would be discriminated against.

I've tried different subclasses, JoinSubclass, etc. no luck, each with different NH exceptions. It only works when both hierarchies are displayed by default with the combined subclass. However, the automapper cannot automatically render IList [int]. If I installed IList [Product] (to test) everything works fine. If I try to store the IList [int] using this mapping:

   public class ListQuantityMap : IAutoMappingOverride<ListQuantity>
   {
      public void Override(AutoMap<ListQuantity> mapping)
      {
         mapping.HasMany(x => x.Quantities).AsElement("QuantitiesId");
      }
   }

      

if System.Xml.Schema.XmlSchemaValidationException fails: element 'class' in namespace 'urn: nhibernate-mapping-2.2' has invalid child element 'bag' in namespace 'urn: nhibernate-mapping-2.2'. The list of expected items is "meta, subselect, cache, synchronize, comment, tuplizer, id, composite-id" in the namespace "urn: nhibernate-mapping-2.2".

although the only difference in exported Orders.Core.Quantity.hbm.xml is a one-to-many class ... i.e. NHibernate doesn't complain about the bag in almost the same mapping.
(note: this is probably a bug and was fixed in recent FNH issue # 299).

In any case, a merged subclass is not a perfect solution here. I even think that I am only making a component in the AppProduct and creating the corresponding quantity object when the "QuantityType" property is assigned to me ... too weird. Or maybe switching to Linq2Sql will help ?; -)

+2


source to share


1 answer


I'm not sure what you are trying to accomplish. It looks like there might be some problems with your object model. For example, it looks like you have a quantity class (as opposed to the standard property obtained, perhaps, int). You might want to rethink this.

If you find that you have problems with AutoMapper, you can go back and use standard (manual) mappings in conjunction with conventions.



I think the problem is most likely with your Object Model, not Fluent-NHibernate problem.

You can find the official free page for subclass mappings http://wiki.fluentnhibernate.org/Fluent_mapping .

+1


source







All Articles