issue using indexOf function in fluent API query

Posted by Community Admin on 03-Aug-2018 22:02

issue using indexOf function in fluent API query

All Replies

Posted by Community Admin on 28-Jan-2011 00:00

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

Posted by Community Admin on 31-Jan-2011 00:00

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

Posted by Community Admin on 01-Feb-2011 00:00

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

Posted by Community Admin on 01-Feb-2011 00:00

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

Posted by Community Admin on 01-Feb-2011 00:00

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

Posted by Community Admin on 01-Feb-2011 00:00

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

Posted by Community Admin on 01-Feb-2011 00:00

hi Ivan,

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

thanks
Dan

Posted by Community Admin on 03-Feb-2011 00:00

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

Posted by Community Admin on 04-Feb-2011 00:00

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

Posted by Community Admin on 04-Feb-2011 00:00

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

This thread is closed