Ah, I'm such a dumb-ass. The reason AutoMappingTester<Subclass> doesn't work is because there isn't a separate mapping (that is, an HBM.XML) for the Subclass. It exists only as a <joined-subclass /> child node of Superclass' mapping file, so if I want to test how Subclass is mapped, I have to create AutoMappingTester<Superclass> and drill into the <joined-subclass /> element.
-- Asbjørn Ulsberg -=|=- [email protected] (mailto:[email protected]) «He's a loathsome offensive brute, yet I can't look away» On torsdag 29. september 2011 at 13:33, Asbjørn Ulsberg wrote: > Just to add to the problems with joined subclasses, it seems that it's > impossible to use AutoMappingTester<T> on a class that is subclass-mapped. > FNH at least throws the following exception in my face: > > System.InvalidOperationException : Could not find mapping for class > 'Subclass' > at > FluentNHibernate.Testing.DomainModel.Mapping.MappingTester`1.ForMapping(ClassMap`1 > classMap) in > fluent-nhibernate\src\FluentNHibernate.Testing\DomainModel\Mapping\MappingTester.cs: > line 73 > at > FluentNHibernate.Testing.Automapping.AutoMappingTester`1..ctor(AutoPersistenceModel > mapper) in > fluent-nhibernate\src\FluentNHibernate.Testing\AutoMapping\AutoMappingTester.cs: > line 16 > > > :-( > > -- > Asbjørn Ulsberg -=|=- [email protected] (mailto:[email protected]) > «He's a loathsome offensive brute, yet I can't look away» > > On onsdag 28. september 2011 at 17:19, Asbjørn Ulsberg wrote: > > > Thanks for your insights! > > > > The things I'm mapping is the Id and foreign key. I've hacked my way around > > all of this by implementing IJoinedSubclassConvention like this: > > > > public class JoinedSubclassConvention : IJoinedSubclassConvention > > { > > private static readonly IList<ClassMapping> joinedSubclasses; > > > > > > static JoinedSubclassConvention() > > { > > joinedSubclasses = new List<ClassMapping>(); > > } > > > > > > public static void Add<T>(AutoMapping<T> mapping) > > { > > ClassMapping classMapping = ((IMappingProvider)mapping).GetClassMapping(); > > joinedSubclasses.Add(classMapping); > > } > > > > > > public void Apply(IJoinedSubclassInstance instance) > > { > > string id = joinedSubclasses > > .Where(mapping => mapping.Type == instance.EntityType) > > .Select(mapping => mapping.Id).OfType<ColumnBasedMappingBase>() > > .SelectMany(mapping => mapping.Columns) > > .Where(column => column.Name != null && column.Name.EndsWith("Id")) > > .Select(idColumn => idColumn.Name) > > .FirstOrDefault(); > > > > if (id != null) > > { > > instance.Key.Column(id); > > instance.Key.ForeignKey(String.Format("FK_{0}_{1}", > > instance.EntityType.Name, id)); > > } > > > > if (instance.EntityType.IsAbstract) > > instance.Abstract(); > > } > > } > > > > > > And then in all IAutoMappingOverride implementations, I do this: > > > > public void Override(AutoMapping<X> mapping) > > { > > // Do the mapping > > JoinedSubclassConvention.Add(mapping); > > } > > > > > > It's lots of things that can be done in IAutoMappingOverride that isn't > > taken into consideration in my JoinedSubclassConvention, but this works for > > Id and foreign keys at least. I would love if this part of FNH could get > > some love in the future and I would be more than happy to test anything > > that improves on how this works at the moment. > > > > Just being able to more easily figure out what an IAutoMappingOverride has > > done, and be able to extract this would be awesome. Even more awesome would > > be if IAutoMappingOverride would actually be useful for subclass-mapped > > entities, so when calling mapping.Id(x => x.Id, "MyId"), the ID column is > > named "MyId", etc. > > > > -- > > Asbjørn Ulsberg -=|=- [email protected] (mailto:[email protected]) > > «He's a loathsome offensive brute, yet I can't look away» > > > > On onsdag 28. september 2011 at 06:44, Isaac Cambron wrote: > > > > > I looked into this for a while (original group post here > > > (http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/617eeaa8fb31935d/c0cd57536e7c642a?lnk=gst&q=isaac#c0cd57536e7c642a)). > > > Basically, subclassing from an override doesn't work at all. I took a > > > stab at fixing it (branch is here > > > (https://github.com/icambron/fluent-nhibernate/tree/discriminate_in_overrides), > > > though I'm not sure what state it's in), and wasn't able to make it work > > > within the timebox I had for it. In fact, it turned out to be really > > > complicated and probably the wrong approach, and I may have to start > > > over. In fact, after attacking it from a few different angles, I'm not > > > even sure it *should* be possible; the Subclass<> method deprecation is > > > actually right, but in the meantime we don't have any other solution. But > > > I'll probably have another go at it in case I missed something. > > > > > > The specific error you're getting isn't hard to fix though, if I'm right > > > about what it is. Basically, AutoSubClassPart only takes a string > > > discriminator in the constructor for some reason, and the reflection code > > > that tries to find it is failing. My branch has a fix for that here > > > (https://github.com/icambron/fluent-nhibernate/commit/b94914453d87e2c3db014bfc371489a7e492344b#src/FluentNHibernate/Automapping/AutoSubClassPart.cs), > > > and also some tests about it. OTOH, I suspect that if you pull out that > > > fix, it will only get you to the next failure. > > > > > > TL;DR - mapping.Subclass<Child>(1, () => {}) is very broken. > > > > > > -Isaac > > > > > > On Tue, Sep 27, 2011 at 11:00 AM, James Gregory <[email protected] > > > (mailto:[email protected])> wrote: > > > > Is it just foreign key naming you're doing, or more? Have you seen the > > > > ForeignKeyConvention base class? You might be able to use that instead; > > > > but either way, that class implements IJoinedSubclassConvention so it > > > > might give you some ideas. > > > > > > > > Documentation on this area is sparse; frankly, because it's crap. > > > > > > > > -- > > > > You received this message because you are subscribed to the Google > > > > Groups "Fluent NHibernate" group. > > > > To view this discussion on the web visit > > > > https://groups.google.com/d/msg/fluent-nhibernate/-/9H4Fa-MP1lwJ. > > > > > > > > To post to this group, send email to > > > > [email protected] > > > > (mailto:[email protected]). > > > > To unsubscribe from this group, send email to > > > > [email protected] > > > > (mailto:fluent-nhibernate%[email protected]). > > > > For more options, visit this group at > > > > http://groups.google.com/group/fluent-nhibernate?hl=en. > > > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Fluent NHibernate" group. > > > To post to this group, send email to [email protected] > > > (mailto:[email protected]). > > > To unsubscribe from this group, send email to > > > [email protected] > > > (mailto:[email protected]). > > > For more options, visit this group at > > > http://groups.google.com/group/fluent-nhibernate?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.
