Problem with multiple instances of a nested component in an entity.
I'm using Automapping with build 677. I'm getting the error: "Invalid index N for this SqlParameterCollection with Count=N." The error is happening because of how two instances of nested components are mapped. I have two instances of a component that contains a property plus two other components. In the mapping, the component property that isn't nested gets a prefix (member name) appended to the column name, but the columns for the nested components' properties do not get a prefix. I end up with duplicate column names which cause the above error.
Is there a workaround for this?
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by James Gregory on 18 May, 2010 03:04 PM
Could you give me an example of your entities and any configuration you've done of the automapper? I'll investigate your issue later.
3 Posted by MylesRip on 18 May, 2010 04:19 PM
Here is a simplified description:
And the columns produced from Automapping are:
ThisEndFormat
PropertyA1
PropertyA2
PropertyB1
PropertyB2
ThatEndFormat
PropertyA1 (duplicate)
PropertyA2 (duplicate)
PropertyB1 (duplicate)
PropertyB2 (duplicate)
ItemId
Here are the Automapper configuration overrides I'm using:
Please let me know if you need additional information. Thanks!
4 Posted by MylesRip on 18 May, 2010 06:32 PM
I just noticed something that I should help to solve this issue!
I have mapping overrides for both the FormatA and FormatB nested components which I use to override the string length. For example:
If I comment out the previous line, the field maps to the column "FormatAPropertyA1". When it is not commented out, it maps to "PropertyA1".
By simply trying to override the string length, the column name mapping behavior is changed.
Of course what I really need is for it to map to "ThisEndFormatAPropertyA1" representing the multiple levels of nesting. ;-)
Hopefully the above information will help to track down the source of the behavior.
( I tried using a fluent mapping to override the automapping and set the column name for a specific instance of the component, but although the fluent mapping is executed, the column name override is ignored. That is covered in a separate discussion. )
Support Staff 5 Posted by James Gregory on 18 May, 2010 06:52 PM
Thanks for the extra info, I'll investigate when I get home tonight.
Support Staff 6 Posted by James Gregory on 20 May, 2010 03:40 AM
Alright, this issue should be fixed if you get the latest version. Our automapping code that dealt with the column prefixing was naive and didn't consider nested components; it's now a lot more robust.
7 Posted by MylesRip on 20 May, 2010 05:13 PM
Beautiful! I just tried build 1.0.0.680 and it completely resolved this issue. I was able to remove the overrides I was using to get around it. I'm sure this will avert some headaches for quite a few people. :-) Great job! FNH rocks!!
Support Staff 8 Posted by James Gregory on 20 May, 2010 05:23 PM
Great, glad to hear it!
James Gregory resolved this discussion on 20 May, 2010 05:23 PM.