2
votes

I want to get list of VisaCodeIds from visaConfigurationDocuments Table and join with visaCodes Table to get VisaCodeName and I am getting this error for the query below:

     public List<VisaCodesNamesDto> GetVisaCodesNames(List<VisaCodesNamesInputDto> input)
    {


        var result = (from visaConfigurationDocuments in Context.VisaConfigurationDocuments
                      join visaCodes in Context.VisaCodes
                      on visaConfigurationDocuments.VisaCodeId equals visaCodes.VisaCodeId
                      where (input.Any(x => x.VisaId == visaConfigurationDocuments.VisaId && x.VersionNo == visaConfigurationDocuments.VersionNo))
                      select new VisaCodesNamesDto
                      {
                          VisaCodeName = visaCodes.NameAr,
                          VisaId = visaConfigurationDocuments.VisaId,
                          VersionNo = visaConfigurationDocuments.VersionNo
                      }).ToList();

        return result;
    }
}
2
Well, think about how you would translate that LINQ into SQL. What SQL code would represent a non-database object of type List<VisaCodesNamesInputDto> ? Then think about the text of the error message. I'm sure you'll piece it all together.Sam Axe
I know the problem but how to fix it in efficient wayOsama Ahmed
You can run a single variable where clause in your query, then filter by the second variable in memory after the results are returned.Sam Axe

2 Answers

0
votes
public List<VisaCodesNamesDto> GetVisaCodesNames(List<VisaCodesNamesInputDto> input) {
    var ids = input.Select(i => i.VisaId).ToList();
    // filter by a single variable...
    var result = Context.VisaConfigurationDocuments
        .Where(vcd => ids.Contains(vcd.VisaId))
        .Select(vcd => new {
            VisaCodeName = visaCodes.NameAr,
            VisaId = visaConfigurationDocuments.VisaId,
            VersionNo = visaConfigurationDocuments.VersionNo
        })
        .ToList();

    // now filter by the second variable...
    result = result
        .Where(dto => input.Any(i => i.VisaId == dto.VisaId && i.VersionNo == dto.VersionNo)
        .ToList();

    return result;
}
0
votes
        public List<VisaCodesNamesDto> GetVisaCodesNames(List<VisaCodesNamesInputDto>input)
    {


        List<string> filterlist = input.Select(x => x.VisaId.ToString() + "-" + x.VersionNo).ToList();


        var result = (from visaConfigurationDocuments in Context.VisaConfigurationDocuments
                      join visaCodes in Context.VisaCodes
                      on visaConfigurationDocuments.VisaCodeId equals visaCodes.VisaCodeId
                      where filterlist.Any(x => x == visaConfigurationDocuments.VisaId.ToString() + "-" + visaConfigurationDocuments.VersionNo)
                      select new VisaCodesNamesDto
                      {
                          VisaCodeNameAr = visaCodes.NameAr,
                          VisaCodeNameEn = visaCodes.NameEn,
                          VisaId = visaConfigurationDocuments.VisaId,
                          VersionNo = visaConfigurationDocuments.VersionNo
                      }).ToList();

        return result;}

i make a work around solution that solve my issue in converting type of complex object in where clause