Stacie
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.Cus tomReports .CreditHol dDetailsRe sults>
to xxx.Models.CustomsReport.C reditHoldR esultsCont ainers.
Model:
results = resultsContainer; > Cannot implicit convert type System.Collections.Generic
to xxx.Models.CustomsReport.C
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;
}
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; }
}
ASKER
no this does not work same issue... Cannot implicit convert type System.Collections.Generic .List<XXX. Models.Cus tomReports .CreditHol dDetailsRe sults>
to xxx.Models.CustomsReport.C reditHoldR esultsCont ainers.
to xxx.Models.CustomsReport.C
What is the return type of GetReportResults method?
If it is List<XXX.Models.CustomRepo rts.Credit HoldDetail sResults> then you need to change your method GetReportResultsObject return type to:
All your variables shall be consistent to the assigned types.
If it is List<XXX.Models.CustomRepo
public static List<XXX.Models.CustomReports.CreditHoldDetailsResults> GetReportResultsObject(CreditHoldSearchCriteria searchCriteria
, xxx.Models.Employee LoggedInUser
, System.Globalization.CultureInfo systemCultureInfo
)
All your variables shall be consistent to the assigned types.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers 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.
Open in new window
toOpen in new window
Explanation: This line
Open in new window
defines as List<XXX.Models.CustomRepothus you need to put back the container to the correct property