I have a problem in understanding the LINQ to Entites query which does not give me the desired results. I have the following code, which should execute the deferred query and show the results in Silverlight Datagrid.
public List<DispIRTSiteReports> DisplayIRTSiteReportsFilOn(List<IssueTypes> issueType, DateTime fDate, DateTime tDate)
{
try
{
var resultSet = from items in DataContext.IRT_Limited_View
select items;
var iType = issueType.Select(i=>i.IssueName); //contains multiple selected issue type Names
if (issueType.Count != 0)
{
foreach (var type in iType)
{
var copy = type;
resultSet = resultSet.Where(items => items.Type_Text.Equals(copy));
}
}
var newResultSet = (from q in resultSet
where q.Date_Time > fDate && q.Date_Time < tDate
select new DispIRTSiteReports
{
PhExt = q.Phone_Extension,
IssueType = q.Type_Text,
IssueSubType = q.Subtype_Text,
IssueDes = q.Issue_Description
}).ToList();
return newResultSet;
}
catch (Exception ex)
{
throw ex;
}
}
I select multiple IssueType Names and they are stored in var iType, but when I execute the code, the resultSet contains null as the first “foreach” iteration alters the resultSet with the first issueType Name and when second iteration is done, the resultSet cannot match the second IssueType Name and thus the resultSet becomes null.
I would like to know how to query the resultSet without altering the original resultSet so that the resultSet contains the corresponding data of multiple IssueType Names selected. Your help in this regard is very much appreciated.
The problem is that you add the predicates, which translates into
AND. If you useContainsyou get the same semantics asOR:(Note: no
foreachloop)