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
25●3●3●7
I'll send you the source of test project if you need.
I can confirm the issue. It's not related with "virtual fields". Error happens when you use
Contains
/In
over fields obtained withas
operator. Also it's worth to mention that "virtual fields" is a somewhat misleading name. I'd rather call them "calculated fields".