Hi,

I am getting an error with a localization field not working in LINQ query translator. I have a field called "Name" set as a localization field and it works with LINQ everywhere except in the code below:

 [Compiler(typeof(Client), "In_Jax_Region", TargetKind.PropertyGet)]
    public static Expression In_Jax_Region(Expression client)
    {

        Expression<Func<Client, bool>> ex = c => (from f in c.Session.Query.All<Funder>() where f.Name.Contains("Zone Jax") && f.ZipCodes.SingleOrDefault(z => z.ZipCode == c.AddressList.FirstOrDefault().Zip) != null select f).FirstOrDefault() != null;

        return ex.BindParameters(client);
    }

Xtensive.Orm.QueryTranslationException was unhandled by user code HResult=-2146233088 Message=Unable to translate 'Query.All().Where(v => (((v.BondingVisit.Date >= @.StartDate) && (v.BondingVisit.Date <= @.EndDate)) && (v.Visitor.In_Jax_Region == True)))' expression. See inner exception for details. Source=Xtensive.Orm StackTrace: at Xtensive.Orm.Linq.QueryProvider.TranslateTResult at Xtensive.Orm.Linq.QueryProvider.ExecuteTResult at Xtensive.Orm.Linq.Queryable1.GetEnumerator() at Maint.btnSetVisitorsFunder_Click(Object sender, EventArgs e) in c:\Program Develop.Net V4.5.1\WebSites\COICMS_2\Maint.aspx.cs:line 1051 at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) InnerException: System.NotSupportedException HResult=-2146233067 Message=Field 'f.Name' must be persistent (marked by [Field] attribute). Source=Xtensive.Orm StackTrace: at Xtensive.Orm.Linq.Translator.VisitMemberAccess(MemberExpression ma) at Xtensive.Linq.ExpressionVisitor1.Visit(Expression e) at Xtensive.Orm.Linq.Translator.Visit(Expression e) at Xtensive.Linq.ExpressionVisitor.VisitMethodCall(MethodCallExpression mc) at Xtensive.Linq.QueryableVisitor.VisitMethodCall(MethodCallExpression mc) at Xtensive.Orm.Linq.Translator.VisitMethodCall(MethodCallExpression mc) at Xtensive.Linq.ExpressionVisitor1.Visit(Expression e) at Xtensive.Orm.Linq.Translator.Visit(Expression e) at Xtensive.Orm.Linq.Translator.VisitBinary(BinaryExpression binaryExpression) at Xtensive.Linq.ExpressionVisitor1.Visit(Expression e) at Xtensive.Orm.Linq.Translator.Visit(Expression e) at Xtensive.Orm.Linq.Translator.VisitLambda(LambdaExpression le) at Xtensive.Orm.Linq.Translator.VisitWhere(Expression expression, LambdaExpression le) at Xtensive.Orm.Linq.Translator.VisitQueryableMethod(MethodCallExpression mc, QueryableMethodKind methodKind) at Xtensive.Linq.QueryableVisitor.VisitMethodCall(MethodCallExpression mc) at Xtensive.Orm.Linq.Translator.VisitMethodCall(MethodCallExpression mc) at Xtensive.Linq.ExpressionVisitor1.Visit(Expression e) at Xtensive.Orm.Linq.Translator.Visit(Expression e) at Xtensive.Orm.Linq.Translator.VisitSequence(Expression sequenceExpression, Expression expressionPart) at Xtensive.Orm.Linq.Translator.VisitFirstSingle(Expression source, LambdaExpression predicate, MethodInfo method, Boolean isRoot) at Xtensive.Orm.Linq.Translator.VisitQueryableMethod(MethodCallExpression mc, QueryableMethodKind methodKind) at Xtensive.Linq.QueryableVisitor.VisitMethodCall(MethodCallExpression mc) at Xtensive.Orm.Linq.Translator.VisitMethodCall(MethodCallExpression mc) at Xtensive.Linq.ExpressionVisitor1.Visit(Expression e) at Xtensive.Orm.Linq.Translator.Visit(Expression e) at Xtensive.Orm.Linq.Translator.VisitBinary(BinaryExpression binaryExpression) at Xtensive.Linq.ExpressionVisitor1.Visit(Expression e) at Xtensive.Orm.Linq.Translator.Visit(Expression e) at Xtensive.Orm.Linq.Translator.VisitMemberAccess(MemberExpression ma) at Xtensive.Linq.ExpressionVisitor1.Visit(Expression e) at Xtensive.Orm.Linq.Translator.Visit(Expression e) at Xtensive.Orm.Linq.Translator.VisitBinary(BinaryExpression binaryExpression) at Xtensive.Linq.ExpressionVisitor1.Visit(Expression e) at Xtensive.Orm.Linq.Translator.Visit(Expression e) at Xtensive.Orm.Linq.Translator.VisitBinary(BinaryExpression binaryExpression) at Xtensive.Linq.ExpressionVisitor1.Visit(Expression e) at Xtensive.Orm.Linq.Translator.Visit(Expression e) at Xtensive.Orm.Linq.Translator.VisitLambda(LambdaExpression le) at Xtensive.Orm.Linq.Translator.VisitWhere(Expression expression, LambdaExpression le) at Xtensive.Orm.Linq.Translator.VisitQueryableMethod(MethodCallExpression mc, QueryableMethodKind methodKind) at Xtensive.Linq.QueryableVisitor.VisitMethodCall(MethodCallExpression mc) at Xtensive.Orm.Linq.Translator.VisitMethodCall(MethodCallExpression mc) at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e) at Xtensive.Orm.Linq.Translator.Visit(Expression e) at Xtensive.Orm.Linq.Translator.TranslateTResult at Xtensive.Orm.Linq.QueryProvider.TranslateTResult InnerException:

Thank you,

Richard

asked Jul 08 at 15:14

rasxte's gravatar image

rasxte
20151617


2 Answers:

Hello Richard,

That's correct. The Name property of the Funder class is not Persistent. You should have a class derived from Localization<funder>. Try to use it in your query. I wrote following expression

Expression<func<client, bool="">> ex = c => (
     from f in c.Session.Query.All<funderlocalization>()
     where f.Name.Contains("Zone Jax") && 
           f.Target.ZipCodes.Any(z => z.ZipCode == c.AddressList.FirstOrDefault().Zip)
     select f).FirstOrDefault() != null;

It is pretty similar to yours.

answered Jul 11 at 04:40

Alexey%20Kulakov's gravatar image

Alexey Kulakov
51215

Hi Alexey,

I do have localization field "Name" in a base class. The field "Name" works in other LINQ statements just fine, but not in custom LINQ.. See below my classes.

Thank you,

Richard

[HierarchyRoot]
public class BaseEntity : Entity, ILocalizable<BaseEntityLocalization>
{
    [Field, Key]
    public int Id { get; private set; }

    // Localizable field. Note that it is non-persistent
    public string Name
    {
        get { return Localizations.Current.Name; }
        set { Localizations.Current.Name = value; }
    }

    public BaseEntity(): base()
    {

    }

    public BaseEntity(Session session)  : base(session)
    {

    }

}

[HierarchyRoot]
public class BaseEntityLocalization : Localization<BaseEntity>
{
    [Field(Length = 100)]
    public string Title { get; set; }

    [Field(Length = 100)]
    public string Name { get; set; }

    public BaseEntityLocalization(Session session, CultureInfo culture, BaseEntity target)
        : base(session, culture, target) { }
}

public class Organization : BaseEntity
{

    [Field]
    public Organization ParentBranch { get; set; }

    [Field]
    [Association(PairTo = "ParentBranch", OnOwnerRemove = OnRemoveAction.Cascade, OnTargetRemove = OnRemoveAction.Clear)]
    public Organization_EntitySet Branches { get; set; }

    [Field]
    public Address Address {get; set;}

    [Field]
    public Phone Phone { get; set; }

    [Field]
    public Phone Fax { get; set; }

    [Field (Length=128)]
    public string WebUrl { get; set; }

     public Organization()
        : base()
    {

    }

     public Organization(Session session)
        : base(session)
    {

    }

}

 public class Funder : Organization
{

    [Field]
    public Funder_Client_Entity_Set Clients { get; private set; }

    [Field]

    public Funder_FamilyGroup_EntitySet FamilyGroups { get; private set; }

    [Field]
    [Association(PairTo = "Fonder", OnOwnerRemove = OnRemoveAction.Cascade, OnTargetRemove = OnRemoveAction.Clear)]
    public Funder_ZipCodes_EntitySet ZipCodes { get; private set; }

    public Funder()
        : base()
    {

    }

    public Funder(Session session, string Name)
        : base(session)
    {
        this.Name = Name;
    }
}

The Following Code works fine..

  protected void btnSetVisitorsFunder_Click(object sender, EventArgs e)
{

    Xtensive.Orm.Session session = SessionManager.Current.Session;

    bool value = (from f in session.Query.All<Funder>() where f.Name.Contains(COICMS_Utils.Get_FunderName(COICMS_Types.Funders_Type.DOC_Jax)) && f.ZipCodes.SingleOrDefault(z => z.ZipCode == "32099") != null select f).FirstOrDefault() != null;

}

answered Jul 11 at 12:43

rasxte's gravatar image

rasxte
20151617

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