Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniil 10 posts 31 karma points
    Jan 10, 2012 @ 15:57
    Daniil
    0

    umbraco.Linq.Core.Tree<T> and Count() issue

    Hello.

    I am currently having a problem with linq querying on umbraco 4.7.1.

    I have a class for data context which looks like this:

    public partial class CustomerServiceDataContext : UmbracoDataContext {
    ...
    public Tree<Request> Requests
            {
                get
                {
                    return this.LoadTree<Request>();
                }
            }
    ....
    }

    I have a razor script that renders list of requests with paging.

    IEnumerable<CustomerServiceNamespace.Request> requests = from t in ctx.Requests select t;
    *some conditional Where()s*....
    var numberOfItems = requests.Count( );

    The problem is Count().

    I randomly get the following error:

    System.InvalidCastException: Unable to cast type of current object to type of value
       at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
       at umbraco.Linq.Core.Node.NodeDataProvider.LoadFromXml[T](XElement xml, T node)
       at umbraco.Linq.Core.Node.NodeTree`1.GetEnumerator()
       at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
       at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source, Func`2 predicate)
       at ASP._Page_macroScripts_RenderRequestList_cshtml.Execute() c:\inetpub\Umbraco\macroScripts\RenderRequestList.cshtml:column 66

    (Sorry, battling with russian translation for exceptions)

    I also get the same error all the time if I step into the script with debugger. And randomly get same error for some other trees in context. (ex: ctx.Regions.Count()) Couldn't find this cause or simmilarities.

    Any help would be appreciated.

Please Sign in or register to post replies

Write your reply to:

Draft