Click here to Skip to main content
15,899,935 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: get same parameter twice Pin
miss78623-Dec-13 3:50
miss78623-Dec-13 3:50 
GeneralRe: get same parameter twice Pin
Richard Deeming6-Jan-14 8:35
mveRichard Deeming6-Jan-14 8:35 
GeneralRe: get same parameter twice Pin
miss7867-Jan-14 5:50
miss7867-Jan-14 5:50 
GeneralRe: get same parameter twice Pin
Richard Deeming7-Jan-14 8:03
mveRichard Deeming7-Jan-14 8:03 
GeneralRe: get same parameter twice Pin
miss7869-Jan-14 6:25
miss7869-Jan-14 6:25 
GeneralRe: get same parameter twice Pin
Richard Deeming9-Jan-14 7:50
mveRichard Deeming9-Jan-14 7:50 
GeneralRe: get same parameter twice Pin
miss78613-Jan-14 5:03
miss78613-Jan-14 5:03 
GeneralRe: get same parameter twice Pin
Richard Deeming13-Jan-14 7:49
mveRichard Deeming13-Jan-14 7:49 
OK, I think I see the problem. You're combining the filters for multiple parameters by chaining calls to the Where method. This will only return records which match all of the filters. Looking at your data, none of the records match both ID1 = 123 and (Name.Contains("storm") || Name.Contains("prest")).

I'm guessing you want to return records which match any of the filters. In this case, the simplest option is to use the Union method:
C#
var data = db.database_ICs.AsQueryable();
var filteredData = new List<IQueryable<database_IC>>();

if (!string.IsNullOrEmpty(query.name))
{
    var ids = query.name.Split(',');
    foreach (string i in ids)
    {
        filteredData.Add(data.Where(c => c.Name != null && c.Name.Contains(i)));
    }
}

if (!string.IsNullOrEmpty(query.id1))
{
    var ids = query.id1.Split(',');
    foreach (string i in ids)
    {
        filteredData.Add(data.Where(c => c.ID1 != null && c.ID1.Contains(i)));
    }
}

if (!string.IsNullOrEmpty(query.id2))
{
    var ids = query.id2.Split(',');
    foreach (string i in ids)
    {
        filteredData.Add(data.Where(c => c.ID2 != null && c.ID1.Contains(i)));
    }
}

if (query.deal_type != null)
{
    filteredData.Add(data.Where(c => c.Type == query.deal_type));
}

// If no filters passed, return all data.
// Otherwise, combine the individual filters using the Union method
// to return all records which match at least one filter.
if (filteredData.Count != 0)
{
    data = filteredData.Aggregate(Queryable.Union);
}

if (!data.Any())
{
    var message = string.Format("No data was found");
    return Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
}

return Request.CreateResponse(HttpStatusCode.OK, data);




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: get same parameter twice Pin
miss78614-Jan-14 5:08
miss78614-Jan-14 5:08 
GeneralRe: get same parameter twice Pin
Richard Deeming14-Jan-14 10:59
mveRichard Deeming14-Jan-14 10:59 
GeneralRe: get same parameter twice Pin
miss78628-Jan-14 6:52
miss78628-Jan-14 6:52 
QuestionWhat is the best way for managing reports in Kentico CMS 7.0 Pin
Bhushan Patki19-Dec-13 0:32
Bhushan Patki19-Dec-13 0:32 
Answertemp Pin
Ya Rasoolallah18-Dec-13 12:56
Ya Rasoolallah18-Dec-13 12:56 
SuggestionRe: temp Pin
Richard MacCutchan18-Dec-13 22:00
mveRichard MacCutchan18-Dec-13 22:00 
Questionauto complete with ajaxcontroltoolkit and ado.net Pin
Ya Rasoolallah18-Dec-13 12:01
Ya Rasoolallah18-Dec-13 12:01 
AnswerRe: auto complete with ajaxcontroltoolkit and ado.net Pin
thatraja18-Dec-13 13:39
professionalthatraja18-Dec-13 13:39 
GeneralRe: auto complete with ajaxcontroltoolkit and ado.net Pin
Ya Rasoolallah18-Dec-13 14:05
Ya Rasoolallah18-Dec-13 14:05 
GeneralRe: auto complete with ajaxcontroltoolkit and ado.net Pin
thatraja18-Dec-13 14:22
professionalthatraja18-Dec-13 14:22 
GeneralRe: auto complete with ajaxcontroltoolkit and ado.net Pin
Ya Rasoolallah19-Dec-13 6:10
Ya Rasoolallah19-Dec-13 6:10 
AnswerRe: auto complete with ajaxcontroltoolkit and ado.net Pin
joginder-banger25-Dec-13 15:36
professionaljoginder-banger25-Dec-13 15:36 
QuestionAre there any good "substitute" ASP.Net lessons for "C# for programmers 2e"? Pin
That New Guy18-Dec-13 10:47
That New Guy18-Dec-13 10:47 
AnswerRe: Are there any good "substitute" ASP.Net lessons for "C# for programmers 2e"? Pin
Rahul Rajat Singh19-Dec-13 18:23
professionalRahul Rajat Singh19-Dec-13 18:23 
AnswerRe: Are there any good "substitute" ASP.Net lessons for "C# for programmers 2e"? Pin
abdul subhan mohammed21-Dec-13 3:44
professionalabdul subhan mohammed21-Dec-13 3:44 
Questionpass a value from custom text box control to controller Pin
Member 1040952418-Dec-13 10:01
Member 1040952418-Dec-13 10:01 
QuestionComplex UriTemplate for WCF Pin
Siva Kumar Balaguru 18-Dec-13 0:16
Siva Kumar Balaguru 18-Dec-13 0:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.