Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

linq to sql query for extract email which is not in string array

Posted on 2008-06-21
2
Medium Priority
?
221 Views
Last Modified: 2013-11-26
i have array like

string[] email=new string[]{"aa@aa.com","aa1@aa.com"}

now i need to extract all record which does not contail this emails.

0
Comment
Question by:jbajaj
  • 2
2 Comments
 
LVL 21

Expert Comment

by:naspinski
ID: 21836825
I don't understand the question.  I see that you have an array of emails - are you using this to search through a DB that has an email field and you want the records that are *not* in the array?

For example if your array is { "a@email.com", "b@email.com" }

and you table is:
EMAIL
a@email.com
b@email.com
c@email.com
d@email.com

You want the query to return c@email and d@email.com?
0
 
LVL 21

Accepted Solution

by:
naspinski earned 2000 total points
ID: 21836848
If that is the case, this query will return all the records that the [email] column does not contain an email that is inside the array:
var query = from p in db.items where !email.Contains(p.EMAIL) select p;
 
//  'EMAIL' is a column in my table which is named 'items'
//  'db' is my DataContext object

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

886 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