You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MapDynamic with array property always results in a single-member array #57
You can reproduce this easily in your MapDynamicTests if you change the Customer's Order type from ICollection<Order> to Order[] and then try to map a customer with more than one Order. The resulting array will always contain only the final Order.
Looking through the code I think this is caused by the MapCollection method, which for arrays does
var arrayList = new ArrayList { instanceToAddToCollectionInstance };
or in the case where isNewlyCreatedInstance is false
var arrayList = new ArrayList((ICollection)instance);
In both cases shouldn't that instead be
var arrayList = new ArrayList((ICollection)instance) { instanceToAddToCollectionInstance };
Oh, I just merged Slapper into my codebase and did the fix I suggested above myself. I'd make a pull request to upstream it, but this project is obviously not maintained anymore.
@odelvalle The StackOverflow link I posted outlines a very specific example of the mapper returning a single member IEnumerable when there should clearly be multiple items. It also features a terrible solution I sledgehammered into my code to deal with this for now.
Thanks @Flaniga3 but I can´t test this issue using external SQL Query. Please, can you post some test that help me to reproduce this "error" using only slapper.automapper?
I've found a test that better exemplifies the issue in ReadMeTests.
First change the models' Orders and OrderDetails properties from IList to Array, then try running I_Can_Map_Nested_Types_And_Resolve_Duplicate_Entries_Properly_Using_Dynamics. You will actually hit a different bug first, when trying to invoke the array's Contains method in MapCollection, because that's actually an extension method for arrays. The proper invocation in that case is something like:
Activity
Flaniga3 commentedon Nov 11, 2017
@FilipFilipov Not sure if you're still struggling with this, but I ran into this same issue and no one anywhere could help. Finally I came up with this somewhat brutal solution in this stack overflow question: https://stackoverflow.com/questions/47239739/slapper-only-maps-one-object-when-selecting-multiple-objects-from-database. Check my first edit.
FilipFilipov commentedon Nov 11, 2017
Oh, I just merged Slapper into my codebase and did the fix I suggested above myself. I'd make a pull request to upstream it, but this project is obviously not maintained anymore.
Flaniga3 commentedon Nov 11, 2017
@FilipFilipov I might consider taking that route myself. Thanks for posting your solution.
odelvalle commentedon Nov 12, 2017
Hi @FilipFilipov I changed ICollection to array in Order, and this test pass without change anything in MapCollection:
Can you send me any test that fail?
Thanks
Flaniga3 commentedon Nov 13, 2017
@odelvalle The StackOverflow link I posted outlines a very specific example of the mapper returning a single member IEnumerable when there should clearly be multiple items. It also features a terrible solution I sledgehammered into my code to deal with this for now.
odelvalle commentedon Nov 13, 2017
Thanks @Flaniga3 but I can´t test this issue using external SQL Query. Please, can you post some test that help me to reproduce this "error" using only slapper.automapper?
FilipFilipov commentedon Nov 13, 2017
I've found a test that better exemplifies the issue in
ReadMeTests.First change the models'
OrdersandOrderDetailsproperties from IList to Array, then try runningI_Can_Map_Nested_Types_And_Resolve_Duplicate_Entries_Properly_Using_Dynamics. You will actually hit a different bug first, when trying to invoke the array'sContainsmethod inMapCollection, because that's actually an extension method for arrays. The proper invocation in that case is something like:Once you've done that, you should run into my original bug, as your mapped
Customerwill now have only oneOrderDetailsinstead of two.