This is a migrated thread and some comments may be shown as answers.
Dynamically composing expression predicates?
2 Answers 33 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
ayumi hinako
Top achievements
Rank 1
ayumi hinako asked on 09 Dec 2009, 03:48 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Jordan
Telerik team
answered on 10 Dec 2009, 08:32 AM
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.
0
ayumi hinako
Top achievements
Rank 1
answered on 10 Dec 2009, 01:57 PM
Hi Jordan,

It's very helpful. Thank you very much.


Best regards

Ayumi
Tags
General Discussions
Asked by
ayumi hinako
Top achievements
Rank 1
Answers by
Jordan
Telerik team
ayumi hinako
Top achievements
Rank 1
Share this question
or