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

InvalidOperationException accessing attribute of TPH mapped class

2 Answers 58 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
dsg
Top achievements
Rank 1
dsg asked on 16 Jun 2016, 01:44 PM

Hi,

we're using Telerik.DataAccess.2015.3.1221.1 on sqlite.
Our application defines a class TestCase in DB-TableA and a base class ChildOfTsTcCtrlCmd with some derived classes includes a class ControlCommand in a TPH mapping to the same DB-TableB.
TestCase and ChildOfTsTcCtrlCmd are related 1:n.

    public class TestCase {    public IList<ChildOfTsTcCtrlCmd> CmdExecChildren { get; set; }    }
    public abstract class ChildOfTsTcCtrlCmd          { public string Title { get; set; } }
    public class ControlCommand : ChildOfTsTcCtrlCmd { public string Name { get; set; }    }


I define a linq query for TestCases which have a relation to a CommandControls:

Database.GetAll<TestCase>().Where(t0 => (t0.CmdExecChildren.Any(t1 => (t1 is ControlCommand) ? true : false)));
==> OK.

I define a linq query for TestCases which have a relation to a CommandControls, which have a specific Title attribute value. The Title attribute is defined in the base class ChildOfTsTcCtrlCmd:

Database.GetAll<TestCase>().Where(t0 => (t0.CmdExecChildren.Any(t1 => (t1 is ControlCommand) ? (t1 as ControlCommand).Title.Contains("%") : false)));
==> OK.

I define a linq query for TestCases which have a relation to a CommandControls, which have a specific Name attribute value. The Name attribute is defined in the derived class ControlCommand:

Database.GetAll<TestCase>().Where(t0 => (t0.CmdExecChildren.Any(t1 => (t1 is ControlCommand) ? (t1 as ControlCommand).Name.Contains("%") : false)));
==> NOK:

    System.InvalidOperationException was unhandled by user code
      HResult=-2146233079
      Message=An exception occurred during the execution of 'Extent<ObjectModel.TestCase>().Where(t0 => t0.CmdExecChildren.Any(t1 => IIF((t1 Is ControlCommand), (t1 As ControlCommand).Name.Contains("%"), False)))'. Failure: Identifier 'Name' is not a parameter or variable or field of 'ObjectModel.ChildOfTsTcCtrlCmd'. If 'Name' is a property please add the FieldAlias or Storage attribute to it or declare it as a field's alias.
    See InnerException for more details.
    Complete Expression:
    .Call System.Linq.Queryable.Where(
        .Constant<Telerik.OpenAccess.Query.ExtentQueryImpl`1[ObjectModel.TestCase]>(Extent<ObjectModel.TestCase>()),
        '(.Lambda #Lambda1<System.Func`2[ObjectModel.TestCase,System.Boolean]>))

    .Lambda #Lambda1<System.Func`2[ObjectModel.TestCase,System.Boolean]>(ObjectModel.TestCase $t0)
    {
        .Call System.Linq.Enumerable.Any(
            $t0.CmdExecChildren,
            .Lambda #Lambda2<System.Func`2[ObjectModel.ChildOfTsTcCtrlCmd,System.Boolean]>)
    }

    .Lambda #Lambda2<System.Func`2[ObjectModel.ChildOfTsTcCtrlCmd,System.Boolean]>(ObjectModel.ChildOfTsTcCtrlCmd $t1)
    {
        .If (
            $t1 .Is ObjectModel.ControlCommand
        ) {
            .Call (($t1 .As ObjectModel.ControlCommand).Name).Contains("%")
        } .Else {
            False
        }
    }

      Source=Telerik.OpenAccess.35.Extensions
      StackTrace:
           bei Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid)
           bei Telerik.OpenAccess.Query.ExpressionExecution.PerformDatabaseQueryMulti[T](Expression expr, ExecutionSettings settings, Object[] grpVals, Boolean checkOid, QueryOptions options)
           bei Telerik.OpenAccess.Query.Piece`1.ExecuteMultiple()
           bei Telerik.OpenAccess.Query.Piece`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
           bei Vector.ReportViewer.ViewModel.QueryModel.UserQueryModel.QueryObjectModelWithFiltering(NavigatableContainerEntry filterType, FilterExpression filterExpression) in D:\vfs\ReportViewer\trunk\Vector.ReportViewer.ViewModel\QueryModel\UserQueryModel.cs:Zeile 639.
           bei Vector.ReportViewer.ViewModel.QueryModel.UserQueryModel.CreateQueryItems(IQueryable`1& queryItems) in D:\vfs\ReportViewer\trunk\Vector.ReportViewer.ViewModel\QueryModel\UserQueryModel.cs:Zeile 578.
           bei Vector.ReportViewer.ViewModel.NavigatorModels.NavigatableRegistryModel.QueryItems(GenericBindable`1& items) in D:\vfs\ReportViewer\trunk\Vector.ReportViewer.ViewModel\NavigatorModels\NavigatableRegistryModel.cs:Zeile 48.
           bei Vector.ReportViewer.ViewModel.NavigatorModels.UntypedListModel.get_Entities() in D:\vfs\ReportViewer\trunk\Vector.ReportViewer.ViewModel\NavigatorModels\UntypedListModel.cs:Zeile 39.
      InnerException:
           CanRetry=false
           HResult=-2146233088
           Message=Identifier 'Name' is not a parameter or variable or field of 'ObjectModel.ChildOfTsTcCtrlCmd'. If 'Name' is a property please add the FieldAlias or Storage attribute to it or declare it as a field's alias.
           Source=Telerik.OpenAccess.35.Extensions
           StackTrace:
                bei Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQueryImpl(Type resultType, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid)
                bei Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid)
           InnerException:

           
OpenAccess Log:
    Telerik.OpenAccess Information: 416 : sm.compile                  1 LINQ ObjectModel.TestCase Extent<ObjectModel.TestCase>().Where(t0 => t0.CmdExecChildren.Any(t1 => IIF((t1 Is ControlCommand), (t1 As ControlCommand).Name.Contains("%"), False))) {Options:ParallelFetch} fg:[default, -jdoreq]
    Telerik.OpenAccess Error: 416 : Identifier 'Name' is not a parameter or variable or field of 'ObjectModel.ChildOfTsTcCtrlCmd'. If 'Name' is a property please add the FieldAlias or Storage attribute to it or declare it as a field's alias.
    Exception thrown: 'System.InvalidOperationException' in Telerik.OpenAccess.35.Extensions.dll

 

The error message is correct: "Failure: Identifier 'Name' is not a parameter or variable or field of 'ObjectModel.ChildOfTsTcCtrlCmd'."

But I expected the mapper to folllow the type cast of ChildOfTsTcCtrlCmd to ControlCommand.

Is this possible? - Is there a workaround?

Best regards

   dsg


2 Answers, 1 is accepted

Sort by
0
dsg
Top achievements
Rank 1
answered on 04 Aug 2016, 04:00 AM
Can anyone help or give a hint on this problem?
0
dsg
Top achievements
Rank 1
answered on 09 Aug 2016, 02:12 PM

We found a solution:

   Database.GetAll<TestCase>().Where(t0 => t0.CmdExecChildren.Cast<ControlCommand>().Where(y => y.Name.Contains("%")).Any());

This query works.
Tags
Data Access Free Edition
Asked by
dsg
Top achievements
Rank 1
Answers by
dsg
Top achievements
Rank 1
Share this question
or