Solved

linq query with dynamic where's

Posted on 2013-11-13
1
265 Views
Last Modified: 2016-02-10
I am passing in the possibility of 7 parameters into a function  

public string GetFilter(string Var1, string Var2, string Var3, string Var4, string Var5, string Var6, string Var7)

The vars will not always have a value. The Var could be "". I want to build a linq query where my where clause uses the Var if it contains a value. What's the best way to accomplish this with the least amount of code overhead.
0
Comment
Question by:NickMalloy
1 Comment
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 400 total points
ID: 39646677
you can use composition to create your query. it is effective and very easy to read and maintain:

If Not String.IsNullOrEmpty(Var1) Then
     qry = qry.Where(Function(c) If(c.Family Is Nothing, "", c.Family) = Var1)
End If
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now