简体   繁体   中英

Getting error -> System.Linq.Enumerable+WhereSelectListIterator`2[Tdsb.Aris.Pims.Entity.PartnershipFunding,System.String]

private string Paidby
{
    get
    {
        string paidBy = string.Empty;

        if(this.PartnershipFundingEntity!=null)
        {
            paidBy = (PartnershipFundingEntity.Where(x => x.FundingTypeId == 1).Select(y => y.CfPurposeList)).ToString();
        }
        return paidBy;
    }
}

receiving error like ->

System.Linq.Enumerable+WhereSelectListIterator`2[Tdsb.Aris.Pims.Entity.PartnershipFunding,System.String]

Your question suggests an error, but the value seems to be the type name that is pushed into paidBy string :

paidBy = (PartnershipFundingEntity
   .Where(x => x.FundingTypeId == 1)          // where iterator at this point
   .Select(y => y.CfPurposeList))             // WhereSelectListIterator at this point
   .ToString();                               // ToString() returns type name by default

I think you should have something like this:

paidBy = PartnershipFundingEntity
   .Where(x => x.FundingTypeId == 1)
   .First(x => <boolean condition to select one element>)
   .PaidByProp;

This works if a single element is found, otherwise FirstOrDefault should be used and tested for null. I think ?. (null conditional) can be used to narrow to a single instruction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM