Linq - Query a query result agains a list of strings?

You should probably push the first names into the database query, like this: var contacts = dataContext.Contacts. Where(c => firstNames. Contains(c.

FirstName)) Now you used "like" in your sample query, so maybe you want: var contacts = dataContext. Contacts . Where(c => firstNames.

Any(f => c.FirstName. Contains(f))) If you could provide some concrete examples it would help EDIT: If you're really pulling back all the contacts from the database already into (say) a List contacts then you could use: var matchingContacts = from contact in contacts join name in firstNames on contact. FirstName equals name select contact.

You should probably push the first names into the database query, like this: var contacts = dataContext.Contacts. Where(c => firstNames. Contains(c.

FirstName)); Now you used "like" in your sample query, so maybe you want: var contacts = dataContext. Contacts . Where(c => firstNames.

Any(f => c.FirstName. Contains(f))); If you could provide some concrete examples it would help. EDIT: If you're really pulling back all the contacts from the database already into (say) a List contacts, then you could use: var matchingContacts = from contact in contacts join name in firstNames on contact.

FirstName equals name select contact.

I've run into problems doing things like this because of the mixed context (database versus memory). Is it not necessary to bring both sequences into a common context? – Joel Etherton Sep 29 at 13:31 1 @JoelEtherton: It depends what you do, but passing a List into the database query is reasonably common.

The main thing is to do it the right way round so you don't end up bringing the whole database down to the client. – Jon Skeet Sep 29 at 13:36 Be careful with 'Contains'. It could be translated to "SELECT * FROM t WHERE x IN('a','b','c', ...)".

But most SQL implementations limit the length of the list. It might be possible to have a few dozens or hunderts items, but certainly not thousands! – Olivier Jacot-Descombes Sep 29 at 13:43 @OlivierJacot-Descombes: Indeed.

If there are just a few contacts in the database but lots of names in the list, then obviously it's best to pull all the contacts instead. If there are lots of names in the list and lots of contacts in the database, life becomes harder... – Jon Skeet Sep 29 at 13:56 I would like to query the original query so that I am only hitting the database once. – user971210 Sep 29 at 14:18.

First, visit this link, download the class and add it to your App_Code folder: weblogs.asp.net/scottgu/archive/2008/01/... Then be sure to add "using System.Linq. Dynamic;" Then construct your query like this: DatabaseDataContext db = new DatabaseDataContext(); List firstNames = new List(); //--- loop through names and build a where query string WhereClause = string. Empty; for (int I = 0; I = Communities.

Length - 1) WhereClause += "FirstName.ToLower(). Contains(\"" + s + "\") OR "; //--- first name is the field name in the db else WhereClause += "FirstName.ToLower(). Contains(\"" + s + "\")"; } //--- execute query and pass the dynamic where clause IQueryable contacts = db.

Contacts . Where(WhereClause) . OrderBy("FirstName"); Good Luck!

Select * from contacts where contacts. Stackoverflow.com/questions/.../linq-to-sql-query-against-a-list-of-entitie...‎CachedSimilarApr 8, 2009 – class Ingredient { public String Name { get; set; } public Double Amount { get; set; } }. List ... Am I able to query my ingredientsList against my "Ingredients" table, doing a where-clause ... What's exactly the result you want to get?

Forums.asp.net/t/next/1755923‎CachedJan 3, 2012 - 5 posts - 4 authorsLinq query against string array or list RSS ... someone show me the correct syntax for querying a string array with linq? ... var result = arItems. Msdn.microsoft.com/en-us/library/bb397915.aspx‎CachedSimilarLINQ queries can be combined with traditional string functions and regular expressions.

... to create an array of strings that you can then query or modify by using LINQ. ... And you can use LINQ to query or modify the MatchCollection results ... text files on arbitrary boundaries and how to perform queries against each part. Msdn.microsoft.com/en-us/magazine/cc721610.aspx‎CachedSimilarby Jared Parsons - in 389 Google+ circlesThis gives a great deal of flexibility in how you use query results to efficiently scroll .... As XDocument, ByVal name As String) As IEnumerable Return From method In doc.

... be traced directly to the conversion of the LINQ query into a List(Of Object). Social.msdn.microsoft.com › Visual Studio Languages Forums › Visual C#‎CachedSep 17, 2011 - 4 posts - 3 authorsprivate List GenerateRandomStates() { using (var context = new ProfilePhotoDataContext()) { var querystates = from s in context. Vb.net.bigresource.com/Linq-Query-to-compare-if-collection-contains-li...‎CachedFeb 4, 2013 - 35 postsVS 2010 Custom Query Against List.

Assign Result (from LINQ To XML Query) To List(Of String)? Is it wrong? Www.intertech.com › Blog › NET‎CachedNov 4, 2012 – Another important aspect of LINQ to XML is querying the contents of an.

... Assumes the books. Xml file is copied to the output directory of the ... Now that the file is in memory in our XDocument object, we are ready to query against it. Stackoverflow.com/.../linq-query-a-query-result-agains-a-list-of-strings‎CachedSep0 1, 2013 – Its job is to automatically translates any Linq query into a Lucene ... set; } public List Employees { get; set; } public string Country ... Filtering by string comparison on a property var results = from company in session.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions