OpenAccess with Telerik MVC

6 posts, 0 answers
  1. Chris Williams
    Chris Williams avatar
    63 posts
    Member since:
    Oct 2004

    Posted 15 Dec 2009 Link to this post

    I'm using the Telerik MVC components in an MVC app running on top of Azure with the OpenAccess ORM. I was running fine, but then I updated to the most recent Telerik MVC release, which came out on Friday. 

    When I try to do column sorting operations, I get some kind of error.  For example, when sorting a DateTime column, I get this:

    Unable to cast object of type 'OpenAccessRuntime.Relational.sql.exp.BinaryOpExp' to type 'OpenAccessRuntime.Relational.sql.exp.ColumnExp'.

    [InvalidCastException: Unable to cast object of type 'OpenAccessRuntime.Relational.sql.exp.BinaryOpExp' to type 'OpenAccessRuntime.Relational.sql.exp.ColumnExp'.]  
       Telerik.OpenAccess.Query.QueryContext.PerformDatabaseQuery(Type type, Expression expression, Int32& number, Boolean exec, Int32 numSkip, Int32 numTake, String aggregateMethod, ResultConverter& convert) +2383  
       Telerik.OpenAccess.Query.QueryContext.PerformDatabaseQueryMultiple(Expression expression) +370  
       Telerik.OpenAccess.Query.ObjectScopeQuery`2.GetEnumerator() +212  
       Telerik.Web.Mvc.Extensions.EnumerableExtensions.Each(IEnumerable`1 instance, Action`1 action) +180  
       Telerik.Web.Mvc.UI.Grid`1.WriteRows(IGridRenderer`1 renderer) +847  
       Telerik.Web.Mvc.UI.Grid`1.WriteTable(IGridRenderer`1 renderer) +305  
       Telerik.Web.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer) +1249  
       Telerik.Web.Mvc.UI.ViewComponentBase.Render() +296  
       Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.Render() +92  
       ASP.views_shared_transactions_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) +497  
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +220  
       System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +118  
       System.Web.UI.Control.Render(HtmlTextWriter writer) +60  
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +144  
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +583  
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +91  
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +410  
       System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +118  
       System.Web.UI.Control.Render(HtmlTextWriter writer) +60  
       System.Web.UI.Page.Render(HtmlTextWriter writer) +66  
       System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +114  
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +144  
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +583  
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +91  
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +7761  
     

    When I'm sorting a string column, I get this:

    Object reference not set to an instance of an object.

    [NullReferenceException: Object reference not set to an instance of an object.]  
       Telerik.OpenAccess.Query.QueryContext.PerformDatabaseQuery(Type type, Expression expression, Int32& number, Boolean exec, Int32 numSkip, Int32 numTake, String aggregateMethod, ResultConverter& convert) +2383  
       Telerik.OpenAccess.Query.QueryContext.PerformDatabaseQueryMultiple(Expression expression) +370  
       Telerik.OpenAccess.Query.ObjectScopeQuery`2.GetEnumerator() +212  
       Telerik.Web.Mvc.Extensions.EnumerableExtensions.Each(IEnumerable`1 instance, Action`1 action) +180  
       Telerik.Web.Mvc.UI.Grid`1.WriteRows(IGridRenderer`1 renderer) +847  
       Telerik.Web.Mvc.UI.Grid`1.WriteTable(IGridRenderer`1 renderer) +305  
       Telerik.Web.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer) +1249  
       Telerik.Web.Mvc.UI.ViewComponentBase.Render() +296  
       Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.Render() +92  
       ASP.views_shared_transactions_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) +497  
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +220  
       System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +118  
       System.Web.UI.Control.Render(HtmlTextWriter writer) +60  
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +144  
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +583  
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +91  
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +410  
       System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +118  
       System.Web.UI.Control.Render(HtmlTextWriter writer) +60  
       System.Web.UI.Page.Render(HtmlTextWriter writer) +66  
       System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +114  
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +144  
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +583  
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +91  
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +7761  
     

    Can you provide any insight on what might be going wrong?
  2. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 18 Dec 2009 Link to this post

    Hi Chris Williams,

    I am writing to let you know that we successfully reproduced the issue, but we need more time to investigate it. I will write back as soon as we have more specific results.

    All the best,
    Jordan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Chris Williams
    Chris Williams avatar
    63 posts
    Member since:
    Oct 2004

    Posted 18 Dec 2009 Link to this post

    Thanks Jordan, that's great to hear.  I was just about to cut down my app into a sample so that I could upload it to you.

    Please let me know when you've learned something.  I have this running in production (although beta) and I'd like to get it resolved so I can expand my beta.

    Chris
  5. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 19 Dec 2009 Link to this post

    Hello Chris Williams,

    We identified the issue and it is because the sort operations are implemented with expressions that contain Iif operator which OpenAccess cannot correctly translate to SQL when used in OrderBy.
    We added a fix for this issue to our TODO list, but  unfortunately I cannot give you an exact time frame for when this fix will be available at the moment. We will most probably have this issue fixed for Q1 2010, but it is possible that the fix will be available earlier in an internal build. We could notify you when such an internal build is available.

    And for now it seems that your only option is to change the code of the Telerik MVC framework to use expressions without the Iif operator.

    In order to do this you will have to change two files:
    1. in the SortDescriptorCollectionExpressionBuilder.cs in the 2009.Q3.1103\Source\Telerik.Web.Mvc\Infrastructure\Implementation\Sorting folder in the public IQueryable Sort method you will need to change this row:
    var descriptorBuilder = ExpressionBuilderFactory.MemberAccess(queryable.ElementType, memberType, descriptor.Member);
    with this one:
    var descriptorBuilder = new PropertyAccessExpressionBuilder(queryable.ElementType, descriptor.Member, false);

    2. in the PropertyAccessExpressionBuilder.cs file in the 2009.Q3.1103\Source\Telerik.Web.Mvc\Infrastructure\Implementation\Expressions\MemberAccess folder you will need to change the class so that it looks like bellow:
    internal class PropertyAccessExpressionBuilder : MemberAccessExpressionBuilderBase
        {
            public PropertyAccessExpressionBuilder(Type itemType, string memberName) : base(itemType, memberName)
            {
            }
     
            private bool wrapWithIif = true;
     
            public PropertyAccessExpressionBuilder(Type itemType, string memberName, bool wrapWithIif)
                : base(itemType, memberName)
            {
                this.wrapWithIif = wrapWithIif;
            }
     
            public override Expression CreateMemberAccessExpression()
            {
                //if no property specified then return the item itself
                if (string.IsNullOrEmpty(this.MemberName))
                {
                    return this.ParameterExpression;
                }
     
                return ExpressionFactory.MakeMemberAccess(this.ParameterExpression, this.MemberName, this.wrapWithIif);
            }
        }

    I hope this helps.

    Best wishes,
    Jordan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Chris Williams
    Chris Williams avatar
    63 posts
    Member since:
    Oct 2004

    Posted 20 Dec 2009 Link to this post

    Hi Jordan

    Thanks for the update.  I downloaded the source, but there's no build files or VS solution, so it doesn't look like it's really designed for me to edit the source and create a new .dll.  So yes, please let me know when there's an internal build where this issue has been addressed.

    Thanks again,

    Chris
  7. Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 21 Dec 2009 Link to this post

    Hi Chris Williams,
    Yes we will notify you as soon as we have something available.

    Best wishes,
    Dimitar Kapitanov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
DevCraft banner