Solved

LINQ Contains

Posted on 2011-03-16
1
364 Views
Last Modified: 2012-05-11
I have a checkboxlist that works as a filter, I concatenate the values as a comma separated list like here

 protected void Filter_Click(object sender, EventArgs e)
        {
            Collection<string> items = new Collection<string>();
            for (int index = 0; index < FilterWraps.Items.Count; index++)
            {
                if (FilterWraps.Items[index].Selected)
                {
                    items.Add(FilterWraps.Items[index].Value);
                }
            }
            //here you will get selected values
            string selected = String.Join(",", items.ToArray());
            LoadWraps(Take == null ? 10 : Take, Skip == null ? 10 : Skip, selected);
        }


Then on the linq method I do this


private void LoadWraps(int take, int pageSize, string filter)
        {
            Take = take;
            Skip = pageSize;
            using (Entities.EntitiesDataContext dc = new Entities.EntitiesDataContext(SPContext.Current.Site.Url))
            {
                EntityList<Entities.Wrap> wraps = dc.GetList<Entities.Wrap>("Wraps");
                List<Entities.Wrap> listWraps = new List<Entities.Wrap>();
                if (string.IsNullOrEmpty(filter))
                {
                    var wrapsqry = (from row in wraps
                                    where row.ItemLanguage.ToString() == (WebPart.Language == null ? DefaultLanguage : Language)
                                    orderby row.PublicationDate descending
                                    select row).Take(Take).Skip(Skip).ToList();
                    listWraps = (List<Entities.Wrap>)wrapsqry;
                }
                else
                {
                    var wrapsqry = (from row in wraps
                                    where row.ItemLanguage.ToString() == (WebPart.Language == null ? DefaultLanguage : Language)
                                    && row.WrapType.Value.ToString().Contains(filter)
                                    orderby row.PublicationDate descending
                                    select row).Take(Take).Skip(Skip).ToList();
                    listWraps = (List<Entities.Wrap>)wrapsqry;
                }



but the contains is not working. any idea?
0
Comment
Question by:LuisEstebanValencia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 10

Accepted Solution

by:
Nash2334 earned 500 total points
ID: 35147563
Your contains is reversed, you are checking if the SP item value contains the filter, not if the filter contains the value:

&& row.WrapType.Value.ToString().Contains(filter)

should be

&& filter.Contains(filterrow.WrapType.Value.ToString())

Also, note that ToList() can become a very expensive operation when thousands of items are involved.  Good luck.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Securing WEBAPI on Azure 2 55
Convert VB web project to C# 3 66
Access-Control-Allow-Origin 4 45
async questions 5 48
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question