locked
Linq To AX Join Problem RRS feed

  • Question

  • Hi,

    I am trying out relatively new feature "Linq To AX" allowing using Linq queries with AX table proxies. Very nice feature, however I am having some difficulties with the multiple table join, which I scrambled down. The join looks like this:

    QueryProvider provider = new AXQueryProvider(null);
    
    QueryCollection<HcmPositionDetail> positionDetailsCollection = new QueryCollection<HcmPositionDetail>(provider);
    QueryCollection<HcmPosition> positionCollection = new QueryCollection<HcmPosition>(provider);
    QueryCollection<HcmPositionWorkerAssignment> positionWorkerCollection = new QueryCollection<HcmPositionWorkerAssignment>(provider);
    QueryCollection<HcmWorker> workerCollection = new QueryCollection<HcmWorker>(provider);
    QueryCollection<OMOperatingUnit> departmentCollection = new QueryCollection<OMOperatingUnit>(provider);
    
    var result = positionDetailsCollection
    	.Join(positionWorkerCollection, p => p.Position, w => w.Position, (x, y) => new { PositionDetail = x, Worker = y.Worker })
    	.Join(departmentCollection, p => p.PositionDetail.Department, d => d.RecId, (x, y) => new { PositionDetail = x.PositionDetail, Worker = x.Worker, Department = y })
    	.Join(workerCollection, p => p.Worker, w => w.RecId, (x, y) => new { PositionDetail = x.PositionDetail, Worker = y })
    	.Join(positionCollection, p => p.PositionDetail.Position, p => p.RecId, (x, y) => new { PositionDetail = x.PositionDetail, Worker = x.Worker, Position = y })
    	.ToList();

    Invokin ToList() causes NullReferenceException with the following call stack:

       at Microsoft.Dynamics.AX.Framework.Linq.Data.AXQueryFormatter.createFieldExpressionNode(String tableAlias, String columnName, String function, AggregateFunctionType functionType)
       at Microsoft.Dynamics.AX.Framework.Linq.Data.AXQueryFormatter.createFieldExpressionNode(String tableAlias, String columnName)
       at Microsoft.Dynamics.AX.Framework.Linq.Data.AXQueryFormatter.VisitColumn(ColumnExpression column)
       at Microsoft.Dynamics.AX.Framework.Linq.Data.DbExpressionVisitor.Visit(Expression exp)
       at Microsoft.Dynamics.AX.Framework.Linq.Data.AXQueryFormatter.Visit(Expression exp)
       at Microsoft.Dynamics.AX.Framework.Linq.Data.AXQueryFormatter.VisitSelect(SelectExpression select)
       at Microsoft.Dynamics.AX.Framework.Linq.Data.DbExpressionVisitor.Visit(Expression exp)
       at Microsoft.Dynamics.AX.Framework.Linq.Data.AXQueryFormatter.Visit(Expression exp)
       at Microsoft.Dynamics.AX.Framework.Linq.Data.AXQueryFormatter.Format(Expression expression)
       at Microsoft.Dynamics.AX.Framework.Linq.Data.AXQueryProvider.Translate(Expression expression)
       at Microsoft.Dynamics.AX.Framework.Linq.Data.AXQueryProvider.Execute(Expression expression)
       at Microsoft.Dynamics.AX.Framework.Linq.Data.QueryCollection`1.GetEnumerator()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       

    So, am I doing something wrong or is this a bug in the Linq To AX framework?

    Hint: When "Department = x.Department" is removed from the new clause in the last join, exception does not occur anymore. But I need that department :)

    Best regards,

    Edin

    Wednesday, August 21, 2013 3:34 PM

All replies