Overrides from more than one assembly
Hi,
Is it possible to configure overrides from more than one assembly? (I have overrides for common entities in one assembly, and want to have overrides for application specific entities in my application specific assembly)
Calling .UseOverridesFromAssembly(assembly) only seems to use overrides from the first assembly I call this on and ignores the second assembly?
Many thanks in advance for any help.
Ieuan
2 Posted by Ieuan on 08 May, 2010 09:46 AM
Looking at the FluentNHibernate source it looks as though overrides from more than one assembly are supported.
Probably my code causing the problem - will investigate further and report back
3 Posted by Ieuan on 08 May, 2010 10:28 AM
On investigation I think the problem lies in this code (in AutoMappingAlterationCollection). This will only allow one type of alteration (AutoMappingOverrideAlteration) to be added, whereas more than one needs to be allowed for multiple assemblies to work. Debugging shows the alteration being added for the first call of UseOverrides from assembles, and the condition evaluating to false on the second call.
public AutoMappingAlterationCollection Add(IAutoMappingAlteration alteration)
Support Staff 4 Posted by James Gregory on 08 May, 2010 10:40 AM
Interesting. I'm away from the code right now, but if you manage to come up
with any solutions, a pull request would be much appreciated.
5 Posted by Kasi on 07 Jul, 2010 05:04 PM
I downloaded Fluent NHibernate 1.1 and I still don't see this issue addressed. I have multiple assemblies containing AutoMappingOverride's and when I try to call UseOverridesFromAssembly(Assembly assembly) multiple times, it seems like it still only takes the first and ignores any subsequent calls. How can I use multiple mapping override assemblies?
6 Posted by Ieuan Friend on 07 Jul, 2010 06:03 PM
I'll send you the code I commented out to make this work tomorrow
Ieuan
Sent from my iPhone
7 Posted by Ieuan on 17 Jul, 2010 11:09 AM
So I just commented out the if condition in the code above and it all works for me (although possibility exists for the same overrides assembly to be added more than onnce now)
I think the ideal solution would be to change the code to either:
a) support an equality operator that checks the wrapped Assembly inside of AutoMappingOverrideAlteration
b) expose the wrapped Assembly and perform GetType() on that
8 Posted by Łukasz Podolak on 28 Jul, 2010 03:35 PM
I faced the same problem, and I confirm, that solution provided by leuan works. However, I've got a feeling that some automappings are being executed now more than once.
I took a look at source code and tried to improve, however I don't think that I understand it enaugh.
Any hopes that somebody who understands the codebase enaugh could help with a bugfix ?
Anyway, thanks to all of you for this excellent piece of work that saved me tons of effort
9 Posted by Mathieu on 08 Aug, 2010 02:57 PM
Same problem here, cannot add two assemblies with overrides.
I edited line 40 of AutoMappingAlterationCollection.cs from
to
And my usage is ( I have some entities defined in AssmeblyB that inherit from entities in AssemblyA) :
If you don't need inheritance support, you don't need to patch, and just use FHN like this :
10 Posted by Mathieu on 08 Aug, 2010 03:01 PM
Ooops, got the code wrong for second part, corrected version here :