+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / issue using indexOf function in fluent API query

issue using indexOf function in fluent API query

10 posts, 0 answered
  1. Dan
    Dan avatar
    28 posts
    Registered:
    16 Jun 2010
    28 Jan 2011
    Link to this post
    hello,

    I am trying to get all content items that have a specific tag but I get  exception "Invalid method" regarding the use of the indexOf method.  Below is my code.  How should I go about accomplishing this task?

    this.KBList.DataSource = App.WorkWith().ContentItems().Where(n => n.Status == ContentLifecycleStatus.Live && n.TagsText.IndexOf("KB") > -1).Get().Take(this.kbLimit).ToList();

    thanks!
    Dan
  2. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    31 Jan 2011
    Link to this post
    Hello Dan,

    our implementation of LINQ does not support IndexOf method. You can use Contains as an alternative. 

    this.KBList.DataSource = App.WorkWith().ContentItems().Where(n => n.Status == ContentLifecycleStatus.Live && n.TagsText.Contains("KB")).Get().Take(this.kbLimit).ToList();

    Hope this helps.


    Kind regards,
    Ivan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Dan
    Dan avatar
    28 posts
    Registered:
    16 Jun 2010
    01 Feb 2011
    Link to this post
    hi Ivan,

    Thanks for the reply.  I am now getting the following exception when using the code you supplied:

    {"line 1:156: Field \"TagsText\" not found in Class Telerik.Sitefinity.GenericContent.Model.ContentItem. {TagsText [\"TagsText\",<42>,line=1,col=156]}\r\nOriginal Query: DEFINE EXTENT extnt FOR Telerik.Sitefinity.GenericContent.Model.ContentItem; SELECT * FROM extnt AS t1  WHERE t1.appName =  $1 AND (t1.status =  $2 AND t1.TagsText LIKE  $3 =  $4 )"}

    I am using the latest build (4.0.1130.0).

    thanks
    Dan
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    01 Feb 2011
    Link to this post
    Hi Dan,

    The error says that "TagsText" is not found for ContentItem. Do you have this field. Can you paste the code you use?

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Dan
    Dan avatar
    28 posts
    Registered:
    16 Jun 2010
    01 Feb 2011
    Link to this post
    hi Ivan,

    Below is my code:

    protected override void InitializeControls(GenericContainer controlContainer)
            {
                
                var contentManager = ContentManager.GetManager();
                var allContent = contentManager.GetContent();
     
                this.KBList.DataSource = App.WorkWith().ContentItems().Where(n => n.Status == ContentLifecycleStatus.Live && n.TagsText.Contains(" KB ") == true).Get().Take(this.kbLimit).ToList();


    The interesting thing is intellisense is showing that "TagsText" is a property of "n".

    Thanks
    Dan
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    01 Feb 2011
    Link to this post
    Hello Dan,

    Ok, I see what the problem is. Actually you have to use the ID of the item


    var taxID= new Guid("61FF245B-23C7-453F-8DE6-2FF8EC46E125");

    var items = App.WorkWith()
                  .ContentItems()
                  .Where(n => ((IList<Guid>)n.GetValue("HereFieldNameYouWantToGet")).Contains(taxID))
                  .Get();

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Dan
    Dan avatar
    28 posts
    Registered:
    16 Jun 2010
    01 Feb 2011
    Link to this post
    hi Ivan,

    ContentItem "n" does not have a method called GetValue.  Should I be using another method instead?

    thanks
    Dan
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    03 Feb 2011
    Link to this post
    Hi Dan,

    Please make sure that you have reference to

    Telerik.Sitefinity.Model.

    GetValue is part of Telerik.Sitefinity.Model.DataExtensions

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Dan
    Dan avatar
    28 posts
    Registered:
    16 Jun 2010
    04 Feb 2011
    Link to this post
    Hi Ivan,

    The code compiles now, but I am a bit confused as to what the value for taxID should be and what I should pass to GetValue.

    For those that are interested, the following approach works for me.

    ContentManager manager = ContentManager.GetManager();
               IQueryable<ContentItem> allItems = manager.GetContent()
                                                   .Where(n => n.Status == ContentLifecycleStatus.Live);
     
                List<ContentItem> itemList = new List<ContentItem>(1);
               foreach (ContentItem item in allItems)
               {
                   if (item.TagsText.IndexOf(" KB ") > -1)
                       itemList.Add(item);
               }
               this.KBList.DataSource = itemList;

    thanks
    Dan
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    04 Feb 2011
    Link to this post
    Hello Dan,

    taxID is the name of the category or tag you want to filter by.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
10 posts, 0 answered