Content by categories in Beta 2.0

Posted by Community Admin on 03-Aug-2018 23:50

Content by categories in Beta 2.0

All Replies

Posted by Community Admin on 29-Sep-2010 00:00

We upgraded to Beta 2.0 today and are excited about the new features and fixes.

We are having problems displaying content by categories even though we are using the exact same code that worked in Beta 1.0.  Our error is occurring in the
.Where(ci => ((IList<Guid>)ci.GetValue("Category")).Contains(catList[0].Id))
line of code.  When we take this line out (it is the part that is determining which category of content to show), the code works fine displaying all of our generic content blocks. 

Our code is listed below, as well as our full error message.
Thanks,
Ann


namespace SitefinityWebApp.Custom.Widgets
    public partial class Top3Faq : System.Web.UI.UserControl
    
        public string Categories get; set;
        protected void Page_Load(object sender, EventArgs e)
        
 
            TaxonomyManager taxManager = TaxonomyManager.GetManager();
 
            List<HierarchicalTaxon> catList = new List<HierarchicalTaxon>();
 
            HierarchicalTaxon hierTaxa = new HierarchicalTaxon();
 
List<string> catStrings = Categories.Split(',').ToList();
 
                foreach (string catString in catStrings)
                
                    string tempString = catString.Trim();
                    hierTaxa = taxManager.GetTaxa<HierarchicalTaxon>().Where(t => t.Name == tempString).Single();
                    catList.Add(hierTaxa);
                
 
                if (HasValue(catList[0].Id))
                
                    var content = App.WorkWith().ContentItems().Where(ci => ((IList<Guid>)ci.GetValue("Category")).Contains(catList[0].Id))
                        .Where(ci => ci.Status == ContentLifecycleStatus.Live);
 
                    List<ContentItem> contentList = content.Get().ToList();
                     
                    linkRepeater.DataSource = contentList;
                    linkRepeater.DataBind();
                
        
 
        private bool HasValue(Guid id)
        
            return SFUtil.HasValue(id);
        
    

Error message:

Exception of type 'Telerik.OpenAccess.SPI.Util.QueryExceptionHelper' was thrown.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Telerik.OpenAccess.SPI.Util.QueryExceptionHelper: Exception of type 'Telerik.OpenAccess.SPI.Util.QueryExceptionHelper' was thrown.

Source Error:

Line 69: 						.Where(ci => ci.Status == ContentLifecycleStatus.Live);
Line 70: 
Line 71: 					List<ContentItem> contentList = content.Get().ToList();
Line 72: 					
Line 73: 					linkRepeater.DataSource = contentList;

Source File: C:\Projects\Murray\CollegeCosts\Source\NCCC Solution\CMS\Custom\Widgets\FeaturedFaq.ascx.cs    Line: 71

Stack Trace:

[QueryExceptionHelper: Exception of type 'Telerik.OpenAccess.SPI.Util.QueryExceptionHelper' was thrown.]

[QueryException: line 1:606: unexpected token: [")",<8>,line=1,col=606]
Original Query: DEFINE EXTENT extnt FOR Telerik.Sitefinity.GenericContent.Model.ContentItem; SELECT  t1  FROM extnt AS t1 , t1.permissions AS t2  WHERE (((t1.InheritsPermissions =  $1 AND (t2.objectId <> t1.Id OR (t2.objectId = t1.Id AND  NOT (EXISTS x IN t1.Permissions :(((x.setName = t2.setName AND x.principalId = t2.principalId ) AND x.objectId <> t2.objectId ) ) ) ) ) ) OR (t1.InheritsPermissions =  $2 AND t2.objectId = t1.Id ) ) AND ((t2.grant >  $3 AND t2.setName =  $4 ) AND (t2.principalId =  $5  OR t2.principalId =  $6  OR t2.principalId =  $7 ) ) ) AND t1.appName =  $8 AND EXISTS x IN t1.Category : ( x = ) AND t1.status =  $9]
   Telerik.Sitefinity.Data.Linq.Oql.OqlQueryProvider`2.ExecuteKnownType(IObjectScope scope, String queryText, Boolean isEnumerable, Int32 skip, Int32 take, IList parameters, ElementOperator op) +1582
   Telerik.Sitefinity.Data.Linq.Oql.OqlQueryProvider`2.Execute(Expression expression) +897

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +0
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +639
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +38
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +35
   Telerik.Sitefinity.Data.Linq.LinqQuery`2.GetEnumerator() +32
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +382
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +80
   SitefinityWebApp.Custom.Widgets.Top3Faq.Page_Load(Object sender, EventArgs e) in C:\Projects\Murray\CollegeCosts\Source\NCCC Solution\CMS\Custom\Widgets\FeaturedFaq.ascx.cs:71
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.UI.Control.LoadRecursive() +71
   System.Web.UI.Control.LoadRecursive() +190
   System.Web.UI.Control.LoadRecursive() +190
   System.Web.UI.Control.LoadRecursive() +190
   System.Web.UI.Control.LoadRecursive() +190
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3048


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

Posted by Community Admin on 01-Oct-2010 00:00

Hi Ann,

The problem is in the way that you pass the catlist[0].Id. You are doing this directly inside Contains and the parser cannot evaluate it which results in an incorrect query. You need to create a variable which represents the ID and then pass it to the Contains, so that you will not evaluate the expression inside Contains

var itemId = catList[0].Id;
var content = App.WorkWith().ContentItems().Where(ci => (ci.GetValue<IList<Guid>>("Category")).Contains(itemId))
.Where(ci => ci.Status == ContentLifecycleStatus.Live);
List<ContentItem> contentList = content.Get().ToList();


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