Link to home
Start Free TrialLog in
Avatar of Stacie
StacieFlag for United States of America

asked on

Cannot implicit convert type System.Collections.Generic.List

I'm getting an exception in my following line of code in my function.  My goal is to return the value of my resultsContainer if my switch statement is invoked.

            results = resultsContainer;  > Cannot implicit convert type System.Collections.Generic.List<XXX.Models.CustomReports.CreditHoldDetailsResults>
to xxx.Models.CustomsReport.CreditHoldResultsContainers.


    public static CreditHoldResultsContainer GetReportResultsObject(CreditHoldSearchCriteria searchCriteria
            , xxx.Models.Employee LoggedInUser
            , System.Globalization.CultureInfo systemCultureInfo
            )
        {
            var results = ServiceAssistantService.CustomReports.CreditHoldService.GetReportResults(searchCriteria, LoggedInUser.CultureInfo, LoggedInUser.ID.Trim().ToUpper());
            var resultsContainer = results.reportResults;
            var headerText = "";

            
         
            if (resultsContainer != null && resultsContainer.Any())
            {
                headerText = headerText + "  " + Sxxx.Tools.Language.Translate(Language.Keys.Sort_By, LoggedInUser.CultureInfo) + " : ";
                switch (searchCriteria.SortOrder)
                {
                    case 1:
                        resultsContainer = resultsContainer.OrderBy(x => x.CustomerNumber).ToList();
                        break;
                    case 2:
                        resultsContainer = resultsContainer.OrderByDescending(x => x.SortName).ToList();
                     break;
     
                }
            }

            results = resultsContainer;
            results.HeaderText = headerText;

            return results;
        }

Open in new window


Model:

public class CreditHoldSearchCriteria : CustomReportsSearchCriteria
    {
        public CreditHoldSearchCriteria()
        {
            FavoriteReportName = CustomReportsNames.CreditHold;
        }
        public string[] SelectedStatusCodes { get; set; }
    }
    public class CreditHoldDetailResults : CustomReportsCustomerDetails
    {
        public string SortName { get; set; }
        public string CollectionCode { get; set; }
        public decimal CreditLimit { get; set; }
        public decimal Due1 { get; set; }
        public decimal Due2 { get; set; }
        public decimal Due3 { get; set; }
        public decimal Due4 { get; set; }
        public decimal Due5 { get; set; }
        public decimal Due6 { get; set; }
        public decimal Due7 { get; set; }
    }
    public class CreditHoldResultsContainer
    {
        public AgingBucketContainer AgingBucket { get; set; }
        public List<CreditHoldDetailResults> reportResults { get; set; }
        public string HeaderText { get; set; }
    }

Open in new window

Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Change line:
results = resultsContainer;

Open in new window

to
results.reportResults = resultsContainer;

Open in new window


Explanation: This line
 var resultsContainer = results.reportResults;

Open in new window

defines as List<XXX.Models.CustomReports.CreditHoldDetailsResults>
thus you need to put back the container to the correct property
Avatar of Stacie

ASKER

no this does not work same issue... Cannot implicit convert type System.Collections.Generic.List<XXX.Models.CustomReports.CreditHoldDetailsResults>
to xxx.Models.CustomsReport.CreditHoldResultsContainers.
What is the return type of GetReportResults method?
If it is List<XXX.Models.CustomReports.CreditHoldDetailsResults> then you need to change your method GetReportResultsObject return type to:
public static List<XXX.Models.CustomReports.CreditHoldDetailsResults> GetReportResultsObject(CreditHoldSearchCriteria searchCriteria
            , xxx.Models.Employee LoggedInUser
            , System.Globalization.CultureInfo systemCultureInfo
            )

Open in new window


All your variables shall be consistent to the assigned types.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.