-
Notifications
You must be signed in to change notification settings - Fork 76
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
MapDynamic with array property always results in a single-member array #57
Comments
@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. |
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. |
@FilipFilipov I might consider taking that route myself. Thanks for posting your solution. |
Hi @FilipFilipov I changed ICollection to array in Order, and this test pass without change anything in MapCollection: [Test]
public void Can_Handle_Mapping_A_Single_Dynamic_Object_With_Multiple_Childs()
{
// Arrange
dynamic dynamicCustomer = new ExpandoObject();
dynamicCustomer.Id = 1;
dynamicCustomer.FirstName = "Bob";
dynamicCustomer.LastName = "Smith";
dynamicCustomer.Orders = new[]
{
new Order {Id = 1, OrderTotal = 50.50m},
new Order {Id = 2, OrderTotal = 60.50m},
};
// Act
var customer = Slapper.AutoMapper.MapDynamic<Customer>(dynamicCustomer) as Customer;
// Assert
Assert.NotNull(customer);
Assert.That(customer.Orders.Count() == 2);
} Can you send me any test that fail? |
@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 First change the models'
Once you've done that, you should run into my original bug, as your mapped |
You can reproduce this easily in your
MapDynamicTests
if you change the Customer's Order type fromICollection<Order>
toOrder[]
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 doesor in the case where
isNewlyCreatedInstance
is falseIn both cases shouldn't that instead be
The text was updated successfully, but these errors were encountered: