This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello I am trying to run this relatively simple linq query but I am finding the ternary statement is not supported. IQueryable<MyEvent> myEventQuery = from o in myEventsCollection where
[NotSupportedException: This expression type is not supported in LightSpeed 3.0] It is very urgent. Many thanks in advance. Cheers, Scott |
|
|
Giving it a bit more thought - I don't think its a Ternary statement problem but rather the use of the type DayOfWeek. Any suggestions?
Thanks |
|
|
OK sorry for the vast number of posts - I just tried using the type DayOfWeek without the ternary statement and it works fine. So the first post does stand as the problem. The problem IS with the Ternary statements. Cheers, Scott |
|
|
Hi Scott, Unfortunately we dont currently support the ternary statement in our LINQ provider. You could however look at a different approach for your original query where you use a switch statement to append the appropriate additional criteria assuming this fits with my understanding that day is a local variable: e.g. public IQueryable<MyEvent> GetEventQuery(DayOfWeek day) { var query = from o in myEventsCollection where o.ContactId == ContactId select o;
case DayOfWeek.Monday: query = query.Where(o => o.Monday == true); break; [...] } return query; }
Would that fit for your scenario?
Jeremy |
|
|
I see how it would work, unfortunately would that not create two database queries? - And using this query in a loop so that may be some unneccessary overhead. I have got it to work by converting my Events collection to a List<MyEvent> before the loop and can run my original query. Is there any plans to include ternary at any point?
Thanks for your help, Scott |
|
|
No, it won't create two database queries. Recall LINQ query execution is deferred until you do a foreach or ToList or whatever. So the first line of Jeremy's code merely creates a query object -- it does not run the query against the database. Then his switch statement adds a clause to that query object. At some later point, this expanded query gets foreach-ed or ToList-ed or Count-ed or whatever, and THEN it hits the database -- with the WHERE clause added by the switch in place. |
|
|
Thanks Ivan for clearing that up. Thats good to know - I think I will need to get a book on linq to get a proper understanding, I am sure I am not using it enough! Thanks again for all the hard work you, and the rest of the team put into this product, I honestly can't think of a programming tool I value so much - and I can't imagine database programming without it. |
|