I have 3 contexts for 3 different servers. The main application data uses context1 connecting to SQL1. In a Web API service I get people records asynchronously from context2 connecting to SQL2. It returns 4800+ records. The records are further filtered against the userFacility which is a result of a stored procedure from context3 connecting to SQL3.
All approaches work on my development machine with Visual Studio 2019 and IIS Express. When published to the IIS Server on our network only the Approach 2 work. It seems the EF only likes a constant value in the inner expression but not a variable value. Does anyone know what the problem might be?
IEnumerable<PeopleDTO> people= await aHelper.GetPeopleAsync(aRepository, defaultQuarter, criteria);
/* sample Facility property of People values are
(1V01) (402) Togus, ME
(1V01) (518) Bedford, MA
(1V01) (523) Boston, MA
(1V01) (608) Manchester, NH
(1V01) (631) Central Western Massachusetts
(3V12) (587) Eastern Colorado, CO
*/
List<string> userFacilities = new List<string>(){“608”,”518”,”674”, "587","648"};
/* approach 1 works in VS but not in IIS */
pepole= pepole.Where(x => userFacilities.Any(y=> x.Facility.Contains(y)));
/* approach 2 works in both in VS and IIS */
pepole= pepole.Where(x => userFacilities.Any(y=> x.Facility.Contains("587")));
/* Approach 3 works in VS but not in IIS */
List<PeopleDTO> viewablePeople = new List<PeopleDTO>();
foreach (PeopleDTO p in people)
{
foreach (string y in userFacilities)
{
/* doesn't work in IIS but works in VS IIS Express if y is a constant*/
if (p.Facility.IndexOf(y) >= 0)
{
viewablePeople.Add(p);
break;
}
}
}
return Ok(viewablePeople);
public partial class PeopleDTO
{
[DisplayName("Facility")]
public string Facility { get; set; }
[DisplayName("District")]
public string District { get; set; }
[DisplayName("Name")]
public string Name { get; set; }
[DisplayName("SSN")]
public string PTFSSN { get; set; }
[DisplayName("FSOD SSN")]
public string FSODSSN { get; set; }
[DisplayName("Fiscal Period")]
public string FiscalPeriod { get; set; }
[DisplayName("Numeric Fiscal Period")]
public int FiscalPeriodInt { get; set; }
[DisplayName("Episode")]
public IEnumerable<EpisodeDTO> Episodes { get; set; }
public PeopleDTO() {
Episodes = new List<EpisodeDTO>();
}