Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing constructor exception when using subclass automapping #418

Closed
kYann opened this issue Aug 24, 2018 · 1 comment
Closed

Missing constructor exception when using subclass automapping #418

kYann opened this issue Aug 24, 2018 · 1 comment
Labels
Milestone

Comments

@kYann
Copy link

kYann commented Aug 24, 2018

Hello,

When using subclass automapping, and setting the discriminated value, if the discriminated value is not a string the AutoSubClassPart object can't be created.

System.MissingMethodException : Constructor on type
'FluentNHibernate.Automapping.AutoSubClassPart`1
[[Something.Model.Sender, Something.Core, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null]]' not found.

This is due to the fact that the AutoSubClassPart constructor takes a string as a discriminated value, if we give anything different than a string Activator.CreateInstance can't find the constructor.

public AutoSubClassPart<TSubclass> SubClass<TSubclass>(object discriminatorValue, Action<AutoSubClassPart<TSubclass>> action)
where TSubclass : T
{
var genericType = typeof(AutoSubClassPart<>).MakeGenericType(typeof(TSubclass));
var subclass = (AutoSubClassPart<TSubclass>)Activator.CreateInstance(genericType, null, discriminatorValue);
if (action != null)
action(subclass);
// remove any mappings for the same type, then re-add
providers.Subclasses[typeof(TSubclass)] = subclass;
return subclass;
}

public void Override(AutoMapping<Sender> mapping)
{
	mapping.DiscriminateSubClassesOnColumn("__type");
	mapping.SubClass<SpecialSender>(0);
}
@hazzik
Copy link
Member

hazzik commented Sep 20, 2020

Inline Subclass definitions never worked with the AutoMapping<>, see #51

With #469 you can now set DiscriminatorValue on subclass:

public void Override(AutoMapping<SpecialSender> mapping)
{
	mapping.DiscriminatorValue(0);
}

@hazzik hazzik closed this as completed in 2a96c74 Sep 20, 2020
@hazzik hazzik added this to the 3.0.0 milestone Sep 20, 2020
@hazzik hazzik added the bug label Sep 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants