Hello! I've found a trouble "Unable to translate expression" if expression contains the filtering of virtual field with the "IN". Inner exception is ArgumentOutOfRangeException. We have exception when Id is Guid at the production DB, but when Id of Int type exception the same.

Example:


var list = Session.Current.Query.All<routingsheet>();
var busType = Session.Current.Query.All<transportationtype>().First(z => z.Name.Contains("Пассаж")).Id;

try { var filtered = list.Where(z => z.TransportationType.Id.In(new[] { busType })).ToArray(); } catch (StorageException e) { throw e; }


namespace Project1.Model
{
    using System;
    using System.Linq.Expressions;
    using Xtensive.Core;
    using Xtensive.Linq;
    using Xtensive.Orm;

    [HierarchyRoot]
    [Serializable]
    class Vehicle : Entity
    {
        [Field, Key]
        public int Id { get; private set; }

        [Field]
        public string Name { get; set; }
    }

    [Serializable]
    class Bus : Vehicle
    {
        [Field]
        public int PassengersCapacity { get; set; }

        [Field]
        public VehicleType Type { get; set; }
    }

    [Serializable]
    class Truck : Vehicle
    {
        [Field]
        public int CarryingCapacity { get; set; }

        [Field]
        public VehicleType Type { get; set; }
    }

    [Serializable]
    [HierarchyRoot]
    class VehicleType : Entity
    {
        [Field, Key]
        public int Id { get; private set; }

        [Field]
        public TransportationType TransportType { get; set; }
    }

    [Serializable]
    [HierarchyRoot]
    class TransportationType : Entity
    {
        [Field, Key]
        public int Id { get; private set; }

        [Field]
        public string Name { get; set; }
    }

    [HierarchyRoot]
    [Serializable]
    class RoutingSheet : Entity
    {
        [Field, Key]
        public int Id { get; private set; }

        [Field]
        public Vehicle Car { get; set; }

        [Field]
        public string SourceAddress { get; set; }

        [Field]
        public string TargetAddress { get; set; }

        [Field]
        public DateTime DateStart { get; set; }

        public TransportationType TransportationType
        {
            get { return TransportationTypeExpressionCompiled(this); }
        }

        private static readonly Expression<func<routingsheet, transportationtype="">> TransportationTypeExpression = obj => (obj.Car as Bus).Type.TransportType;
        private static readonly Func<routingsheet, transportationtype=""> TransportationTypeExpressionCompiled = TransportationTypeExpression.Compile();

        [CompilerContainer(typeof(Expression))]
        public static class CustomLinqCompilerContainer
        {
            [Compiler(typeof(RoutingSheet), "TransportationType", TargetKind.PropertyGet)]
            public static Expression Depositary(Expression assignmentExpression)
            {
                return TransportationTypeExpression.BindParameters(assignmentExpression);
            }
        }
    }
}

asked Dec 06 '12 at 08:43

abelkin's gravatar image

abelkin
25337

edited Dec 06 '12 at 09:04

I'll send you the source of test project if you need.

(Dec 06 '12 at 09:02) abelkin abelkin's gravatar image

I can confirm the issue. It's not related with "virtual fields". Error happens when you use Contains/In over fields obtained with as operator. Also it's worth to mention that "virtual fields" is a somewhat misleading name. I'd rather call them "calculated fields".

(Dec 07 '12 at 06:20) Denis Krjuchkov Denis%20Krjuchkov's gravatar image

One Answer:

Finally fixed and will be included in 4.5.7 and 4.6.3 releases

answered Dec 27 '12 at 03:52

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov
179325

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA