Git Product home page Git Product logo

Comments (14)

sdanyliv avatar sdanyliv commented on July 21, 2024 1

@esskar, in our QueryProvider we have used the following transformation:
https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Linq/Builder/ExpressionBuilder.cs#L297
It works very well for such big filter conditions.
Exactly before serialization, just transform expression.

from serialize.linq.

vsoldatkin avatar vsoldatkin commented on July 21, 2024

Could you please attach a code snippet representing your expression?

I doubt there will be an easy fix for this though. This behavior is actually expectable.

from serialize.linq.

esskar avatar esskar commented on July 21, 2024

as @vsoldatkin stated: we need the original expression that causes that error.
But it looks like you should rethink your expression
x.Account >= 799 && x.Account <= 0 seems to be an alternative here

from serialize.linq.

lovemyselfbest avatar lovemyselfbest commented on July 21, 2024

@vsoldatkin @esskar , thanks for reply.
I have a collection, the collection could contain guid or string or something else type data , for example,
x=>collection.contain(x.Id) , I want to send this expression from asp.net mvc client to wcf server, so i need serialize this expression, but collection cannot pass to server, so I modify it to x.Id=='constant value1 from collection' || x.Id=="**" ... , by this method, the collection's data can be passed to server, the wcf server accepts the expression ,and then passes it to nhibernate.
In asp.net mvc environment , when the collection has 800 objects , then invoke "ToExpressionNode", the statck overflow exception will appear.
In console environment , when the collection has 5000 objects , then invoke "ToExpressionNode", the statck overflow exception will appear.
I estimate that it has relationship with the thead's stack size. this is my code, thanks.

class Program
    {
        static void Main(string[] args)
        {
            IList<Guid> idCollection = new List<Guid>();
            for (int i = 0; i < 5000; i++)
            {
                idCollection.Add(Guid.NewGuid());
            }

            var propertyInfo = typeof(User).GetProperty("Id");
            var userParam = Expression.Parameter(typeof(User), "x");
            var propertyExpression = Expression.Property(userParam, propertyInfo);
            Expression composedExpression = Expression.Constant(false, typeof(bool));

            for (int i = 0; i < idCollection.Count; i++)
            {
                Expression equalExpression = Expression.MakeBinary(ExpressionType.Equal, propertyExpression, Expression.Constant(idCollection[i]));
                composedExpression = Expression.MakeBinary(ExpressionType.OrElse, equalExpression, composedExpression);
            }
            var expressionNode = composedExpression.ToExpressionNode();

        }
    }
    class User
    {
        public Guid Id
        {
            get;
            set;
        }
    }

_2015-02-14_09-46-56

from serialize.linq.

esskar avatar esskar commented on July 21, 2024

not sure if i want to support this.
i am build the expression tree using recursion, to change it, i would need to build my own stack; i have to evaluate if it is worth it

from serialize.linq.

esskar avatar esskar commented on July 21, 2024

idea: special collections where the values get serialized when used in expressions!?

or an extension method like

public static void MarkAsConstant(this object) { ... }

so i could mark a variable and when this variable gets used in an expression, we serialise the values like i do for other constant variables

from serialize.linq.

vsoldatkin avatar vsoldatkin commented on July 21, 2024

There is a quick method to linearize the algorithm by spawning Tasks in NodeFactory.Create. It adds a huge overhead without asyncs and a not-so-huge overhead using asyncs. But the latter is incompatible with SL version. I've implemented it as a proof of concept. See vsoldatkin/Serialize.Linq@c2ebe74

I'm afraid it might be neccessary to finally redesign the algorithm introducing custom stack-like "task" storage, probably on a NodeFactory level.

from serialize.linq.

esskar avatar esskar commented on July 21, 2024

Thanks for that.
Yet i thought about a new NodeFactoy implementation, but i was to busy to actually do it.
Maybe on the weekend.

from serialize.linq.

MDR-DEV-GIT avatar MDR-DEV-GIT commented on July 21, 2024

Wouldn't it perhaps be better (both architecturally and as a feature that benefits more than the fringe 800 expression case) to instead support a .WhereIn()/IndexOf().

Or perhaps (if not) supported (otherwise encourage usage of) an expression similar to (from n in p where (from o in list select o).Contains(n.prop) select n);

from serialize.linq.

esskar avatar esskar commented on July 21, 2024

i started a new branch for that (https://github.com/esskar/Serialize.Linq/tree/feature/non_recursive). the idea works, but some unit tests are borked

from serialize.linq.

esskar avatar esskar commented on July 21, 2024

@sdanyliv thanks. will look at it.

from serialize.linq.

esskar avatar esskar commented on July 21, 2024

@sdanyliv i looked further into your suggestions. do i need to adopt only your referenced function or do i also need to implement the Transform extension. i understand, that the Transform extension applies the transformation function first, and if the result does not differ, goes on with the actual transformation.

never mind.

from serialize.linq.

esskar avatar esskar commented on July 21, 2024

fixed with version 1.7.1
thanks for the help

from serialize.linq.

sdanyliv avatar sdanyliv commented on July 21, 2024

URW, it was long way until we invented acceptable solution, so iā€™m glad it helped someone else.

from serialize.linq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.