troubleshooting Question

In LINQ How can I select all with a where parameter

Avatar of DangerMode
DangerMode asked on
.NET ProgrammingASP.NETSQL
10 Comments1 Solution1377 ViewsLast Modified:

Say I have a LINQ

<asp:LinqDataSource ID="LinqDataSource4" runat="server"
                                            ContextTypeName="DataClassesDataContext" OrderBy="Serial"
                                            Select="new (Serial, ID)" TableName="Items"
                                            Where="Location == @Location">
                                                <asp:ControlParameter ControlID="ddlLocation" DefaultValue="1" Name="Location"
                                                    PropertyName="SelectedValue" Type="Int32" />
This works

Now the user wants to select all locations
ddLocation is All which is value of 1
then I want the where statement to be

IF(condition_expr, true_expr, false_expr)
 Where="IF (@Location=1,Location<>-1,Location == @Location)"
True_expr would mean return all rows because none of the locations are -1
False_expr would mean use whatever Location is and return only those rows

However I cant seem to get the syntax to work

No applicable method 'IF' exists in type 'Item'

Also, is there a better way to do this?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros