donnytian / Npoi.Mapper

Use this tool to import or export data with Excel file. The tool is a convention based mapper between strong typed object and Excel data via NPOI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nested Property Mapping: MapHelper.GetPropertyInfoByExpression[T](Expression`1 propertySelector) throws an error

bkwdesign opened this issue · comments

commented

Not sure what I'm doing wrong... trying to set up a mapping to my Customer class which has some nested properties to BillingAddress, ServiceAddress, BillingContact, etc. - my excel file is 17,000 lines, with some whitespace rows in certain regions.

System.IndexOutOfRangeException: Index was outside the bounds of the array.

StackTrace:

at Npoi.Mapper.MapHelper.GetPropertyInfoByExpression[T](Expression`1 propertySelector)
at Npoi.Mapper.MapExtensions.Map[T](Mapper mapper, String columnName, Expression`1 propertySelector, Func`3 tryTake, Func`3 tryPut)

The above error is thrown, seemingly, when I try to use the mapper .. here's my code:

    Npoi.Mapper.Mapper m_mapper = new Npoi.Mapper.Mapper("exportContacts.xlsx");

    m_mapper.Map<Customer>("_kftAccountID", o => o.CustomerId)
        .Map<Customer>("accountType", o => o.AccountType)
        .Map<Customer>("addrBilling", o => o.BillingAddress.AddressLine1)
        .Map<Customer>("addrBillingCity", o => o.BillingAddress.City)
        .Map<Customer>("addrBillingCounty", o => o.BillingAddress.County)
        .Map<Customer>("addrBillingState", o => o.BillingAddress.State)
        .Map<Customer>("addrBillingZip", o => o.BillingAddress.ZipCode)
        .Map<Customer>("addrService", o => o.ServiceAddress.AddressLine1)
        .Map<Customer>("addrServiceCity", o => o.ServiceAddress.City)
        .Map<Customer>("addrServiceCounty", o => o.ServiceAddress.County)
        .Map<Customer>("addrServiceState", o => o.ServiceAddress.State)
        .Map<Customer>("addrServiceZip", o => o.ServiceAddress.ZipCode)
        .Map<Customer>("addrServiceAreaSubdivision", o => o.ServiceAreaSubdivision)
        .Map<Customer>("contactBillingCompName", o => o.BillingContact.CompanyName)
        .Map<Customer>("contactBillingEmail", o => o.BillingContact.Email)
        .Map<Customer>("contactBillingNameFirst", o => o.BillingContact.FirstName)
        .Map<Customer>("contactBillingNameLast", o => o.BillingContact.LastName)
        .Map<Customer>("contactBillingNamePrefix", o => o.BillingContact.Prefix)
        .Map<Customer>("contactBillingPhoneFax", o => o.BillingContact.FaxNumber)
        .Map<Customer>("contactBillingPhoneHome", o => o.BillingContact.PhoneHome)
        .Map<Customer>("contactBillingPhoneMobile", o => o.BillingContact.PhoneMobile)
        .Map<Customer>("contactBillingProfessionalTitle", o => o.BillingContact.ProfessionalTitle)
        .Map<Customer>("contactBillingSecondaryName", o => o.BillingContact.SecondaryName)
        .Map<Customer>("contactBillingSecondaryType", o => o.BillingContact.SecondaryType)
        .Map<Customer>("contactBillingWebSite", o => o.BillingContact.WebSite)
        .Map<Customer>("contactServiceName", o => o.ServiceContact.CompanyName)
        .Map<Customer>("contactServiceEmail", o => o.ServiceContact.Email)
        .Map<Customer>("contactServiceNameFirst", o => o.ServiceContact.FirstName)
        .Map<Customer>("contactServiceNamePrefix", o => o.ServiceContact.Prefix)
        .Map<Customer>("contactServicePhoneFax", o => o.ServiceContact.FaxNumber)
        .Map<Customer>("contactServicePhoneHome", o => o.ServiceContact.PhoneHome)
        .Map<Customer>("contactServicePhoneMobile", o => o.ServiceContact.PhoneMobile)
        .Map<Customer>("contactServicePropertyManager", o => o.ServiceContact.PropertyManager)
        .Map<Customer>("contactServiceType", o => o.ServiceContact.Type)
        .Map<Customer>("contactServiceWebSite", o => o.ServiceContact.WebSite);

Sorry about that, I don't think nested properties are supported yet.
I am quite busy recently and any PR will be highly appreciated :)

I also encountered this problem, when will this issue be sloved? thanks!

more than 5 years later, I just added this feature. 😎 will publish in the next release.

implemented in the v6.2