Solved

linq query with dynamic where's

Posted on 2013-11-13
1
267 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

16 Experts available now in Live!

Get 1:1 Help Now