This is a migrated thread and some comments may be shown as answers.

OpenAccess with Telerik MVC

5 Answers 180 Views
Integration with other products
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris Williams
Top achievements
Rank 1
Chris Williams asked on 15 Dec 2009, 07:30 PM
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?

5 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 18 Dec 2009, 05:49 PM
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.
0
Chris Williams
Top achievements
Rank 1
answered on 19 Dec 2009, 01:26 AM
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
0
Jordan
Telerik team
answered on 19 Dec 2009, 10:05 AM
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.
0
Chris Williams
Top achievements
Rank 1
answered on 20 Dec 2009, 07:50 AM
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
0
Dimitar Kapitanov
Telerik team
answered on 21 Dec 2009, 07:37 AM
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.
Tags
Integration with other products
Asked by
Chris Williams
Top achievements
Rank 1
Answers by
Jordan
Telerik team
Chris Williams
Top achievements
Rank 1
Dimitar Kapitanov
Telerik team
Share this question
or