Dynamically composing expression predicates?

Thread is closed for posting
3 posts, 1 answers
  1. ayumi hinako
    ayumi hinako avatar
    17 posts
    Member since:
    Oct 2009

    Posted 08 Dec 2009 Link to this post

    I want to write a LINQ to SQL that maybe contains one or more conditions.  How to write dynamically expression Linq in OpenAccess?
    Thank you.

    Best regards

    Ayumi
  2. Answer
    Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 10 Dec 2009 Link to this post

    Hi ayumi hinako,

    With the latest build of  OpenAccess you can easily create a query using a predicate as in the sample bellow:

    Expression<Func<Customer, bool>> predicate = c => c.Orders.Count > 1;
    IEnumerable<Customer> customers = scope.Extent<Customer>().Where(predicate);

    Notice how the predicate is an Expression and not just a Func. This allows the predicate expression to be translated to SQL. The other important thing to not is that you must have FieldAlias attributes on the properties of your entities like in the Order property bellow:

    [FieldAlias("orders")]
            public IList<Order> Orders
            {
                get
                {
                    if (this.orders == null)
                    {
                        this.orders = new List<Order>();
                    }
                    return this.orders;
                }
            }

    I hope this helps. Do not hesitate to write again if you have more questions or suggestions.


    All the best,
    Jordan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. ayumi hinako
    ayumi hinako avatar
    17 posts
    Member since:
    Oct 2009

    Posted 10 Dec 2009 Link to this post

    Hi Jordan,

    It's very helpful. Thank you very much.


    Best regards

    Ayumi
Back to Top