automapping, overrides, and subclasses

553 views
Skip to first unread message

Isaac Cambron

unread,
Aug 22, 2011, 8:27:56 PM8/22/11
to Fluent NHibernate
I have a sprawling schema that I've automapped using a few conventions and an abstract override class, from which overrides from individual classes inherit. What I'd like to do is handle subclasses in those inherited overrides. It's not totally clear how I should be doing this:

- DiscriminatorPart.SubClass() is deprecated. Why? 
- SubClass() expects a lambda to do the mapping. I don't actually need that because I'm automapping

I assume both of those have to do with not expecting subclassing to be handled by overrides at all. As it is, I've created a subclassing convention that contains all of the discriminator -> class logic, but that divorces it from the rest of the per-class override logic, and it feels awkward and unobvious. 

Anyway, the question: how should subclassing be handled by overrides?

Thanks,
Isaac

James Gregory

unread,
Aug 23, 2011, 8:50:50 AM8/23/11
to fluent-n...@googlegroups.com
It's been a while since I've done any work on the Automapper, so I may have forgotten how it works...

Is there a reason why you can't just create an override for the subclass type itself (instead of overriding the superclass and calling Subclass)?

Isaac Cambron

unread,
Aug 24, 2011, 12:45:21 PM8/24/11
to fluent-n...@googlegroups.com
I should have been more specific. What I'm really trying to do is set up the discriminator values. So I've got something like:

public void Override(AutoMapping<Thingy> mapping)
{
    var des = mapping.DisciminateSubClassesOnColumn("typeid");
    des
         .SubClass<SubThingy>(m => {}) //a. deprecated, b. weird empty lambda
         .IdentifiedBy("ImASubThingy"); //my discriminator value
}

I'm not sure how I'd do that IdentifiedBy bit in the subclass' override.

On Tue, Aug 23, 2011 at 8:50 AM, James Gregory <jagreg...@gmail.com> wrote:
It's been a while since I've done any work on the Automapper, so I may have forgotten how it works...

Is there a reason why you can't just create an override for the subclass type itself (instead of overriding the superclass and calling Subclass)?

--
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/-/UXQde01voCcJ.
To post to this group, send email to fluent-n...@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.

James Gregory

unread,
Aug 25, 2011, 6:04:55 AM8/25/11
to fluent-n...@googlegroups.com
Ah, I think we've got a hole in our API here. In a non-automapping scenario you'd use a SubclassMap, which gives you a DiscriminatorValue method you can call; sounds like we need that in the overrides to facilitate what I thought was already available.

Does the deprecated method still work?

Isaac Cambron

unread,
Aug 29, 2011, 4:32:18 PM8/29/11
to fluent-n...@googlegroups.com
It doesn't seem to. I haven't dug deep to find out why, but here it is. First, my other email used an old syntax. It should have said this:

mapping
.DiscriminateSubClassesOnColumn("typeid")
.SubClass<SubThingyOne>(1, m => { })
.SubClass<SubThingyTwo>(2, m => { });

which is way nicer (you describe that change here). That first argument to SubClass is an object that serves as the discriminator value. Also, it's relevant to my error message that my discriminator values are integers. Anyway, the result I get from querying is:

Conversion failed when converting the varchar value 'MyNamespace.SubThingyOne' to data type int.

which suggests it's not honoring the discriminator value at all and just passing in the type string.

I don't at all mind digging into the generated mappings and working out the fix. But first I wanted to make sure I'm fixing the right thing, since presumably it was deprecated with good reason. My proposal is this:

1. Fix it if it's broken
2. Undeprecate SubClass()
3. Add an overload SubClass(object discriminatorValue)

Does that sound right? Is there a different way I should tackle it?

-Isaac

On Thu, Aug 25, 2011 at 6:04 AM, James Gregory <jagreg...@gmail.com> wrote:
Ah, I think we've got a hole in our API here. In a non-automapping scenario you'd use a SubclassMap, which gives you a DiscriminatorValue method you can call; sounds like we need that in the overrides to facilitate what I thought was already available.

Does the deprecated method still work?

--
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/-/-1gnz9oNIvkJ.

Isaac Cambron

unread,
Sep 6, 2011, 3:47:21 PM9/6/11
to fluent-n...@googlegroups.com
Bump. Any thoughts here?
Reply all
Reply to author
Forward
0 new messages