linq

LINQ update on joined collections

How do I use LINQ to update objects in one list from objects in a second list? My question is very similar to http://stackoverflow.com/questions/709560/linq-in-line-property-update-during-join except that, in my case, the second list is smaller than the parent list. In other words, I want to update those members of the master collection ...

How to Create a search function with nhibernate, linq?

I am going to build a search function today, c# asp.net. i need a push go get it rolling. i use nhibernate linq. it would be nice to do this with linq query. it need to be kinda dynamic, i am going to have several search criterias like gender, email, name, age and some more. this search query is only going to my customer object. how ...

Selecting most popular Foo by count of Bars

Restated question: I have foo. Foo has many fizzs. Fizz has Foo. Bar has one fizz. I want to find foo, which has fizz with the highest count of bars that reference it using LINQ . It would be perfect, if linq would be NHibernate.Linq compatible. But that's already a different story. Old question: I know - question is simple. I've ...

Usinq Linq to select items that is in a semi-comma separated string?

I have a string with semi-comma separated names: string names = "Jane;Harry"; I also have a list of customer objects: public class Customer { public string FirstName { get; set; } public string LastName { get; set; } } List<Customer> customers = new List<Customer>(); customers.Add(new Customer(){FirstName="John", LastName="Doe"}...

Displaying item other than key with groupby foreach loop c# asp.net mvc

I am currently using groupby with a foreach loop to show a list of nested records. However I want to us an id as the key, so that I can use it to make dynamic css selectors etc.. But I want to be able to show the name of each of the groups before the secondarly loop is iterated through. I think the code will make it more clear. Basic...

How to Remove unneccessary list using lambda and functional C# paradigm

Hello Functional C# Friends, So this time i am trying to compact my code and write in more functional , lambda style, as well as i would like to avaoid creating unneccessary lists and classes and let compiler do the work for me. I did manage to convert some small piece of code in functional way but after that i dont have much idea as ho...

How to convert System.Linq.Enumerable.WhereListIterator<int> to List<int>?

In the below example, how can I easily convert eventScores to List<int> so that I can use it as a parameter for prettyPrint? Console.WriteLine("Example of LINQ's Where:"); List<int> scores = new List<int> { 1,2,3,4,5,6,7,8 }; var evenScores = scores.Where(i => i % 2 == 0); Action<List<int>, string> prettyPrint = (list, title) => { ...

What is the second meaning of a single ampersand in C#?

I have used the single ampersand (&) in C# to mean "check the second conditional statement even if the first is false". But the following seems to be a different meaning of & altogether, can anyone explain how i & 1 works in the following example? List<int> scores = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8 }; var evenScores = scores.Whe...

Linq to SQL - How to inner join tables from different Data Context?

I have two tables from two different Data Contexts. Although both tables are from the same database, two separate datacontexts exist. Error msg: "The query contains references to items defined on a different data context." How can I get around this? Any help is appreciated. Thanks. ...

Fetch rows before and after the actual item using LINQ

I currently have a controller with the following ActionResult public ActionResult Details(string sku) { Product p = _productRepository.GetProduct(sku); return View("Details", p); } I would like to expand on the LINQ query to return the product before as well as the product after to the view. So instead of ...

Linq to Entities query hitting db twice

Hi, I have the following pretty simple linq query querying a linq to entities edmx. (from i in ent.Inspectors select i).OrderBy(s => s.Surname).Skip((page - 1) * count).Take(count).ToList(); In Sql Server Profiler I can see that the exact same select query is being sent twice. Can someone explain why? Cheers, Dave ...

LINQ to SQL: Lazy loading an association

How can I lazy load an association (EntitySet) in LINQ to SQL? You can't set Delay Loaded on Associations in the designer, and I couldn't find a DBML attribute for it either. I looked at DataLoadOptions to see if there was a way to lazy load them that way, but DataLoadOptions really just provides a way to mold the SQL that is generated f...

LINQ debug time code change... is it possible in vs2008?

is there any ways to accomplish this? it is really annoying having to restart every time. ...

How can I build a string from a collection with Linq?

I'm building flat file content from collections of strings. Example collection: A, B, C, D, E, etc. I want to be able to output these values to a string with line feeds in one swoop with Linq if possible. Sample Output: A B C D E etc. Here's the VB.NET code that does the job currently: For Each fieldValue As String In field.Va...

Check if a string has at least one number in it using LINQ

I would like to know what the easiest and shortest LINQ query is to return true if a string contains any number character in it. Thanks Jobi Joy ...

Multiple group by and Sum LINQ

I have a products sales table that looks like this: saleDate prod qty 10/22/09 soap 10 09/22/09 pills 05 09/25/09 soap 06 09/25/09 pills 15 I need to make the SUM of each MONTH so the final table would look like this: saleDate prod qty 10/09 soap 10 09/09 ...

quering a dictionary in a dictionary with LINQ

Here is my problem : I have the following dictionary : Dictionary<double, Dictionary<double, List<string>>>; With LINQ I would like to first 1) Sort this dictionary in descending order, keep the first 20, and work with the second dictionary. 2) With the second dictionary I would like to sort it by descending order , keep the sorted...

Convert downgrade Linq to normal C# .NET 2.0 for domainname-parser codes that use publicsuffix.org

Hi, Based on this answer http://stackoverflow.com/questions/288810/get-the-subdomain-from-a-url, I am trying to use code.google.com/p/domainname-parser/ that will use Public Suffix List from publicsuffix.org to get subdomain and domain for managing my cookie collection. In the current moment, Domainname-parser is the only .NET code I f...

Simple Linq question: How to select more than one column?

Hi, my code is: List<Benutzer> users = (from a in dc.Benutzer select a).ToList(); I need this code but I only want to select 3 of the 20 Columns in the "Benutzer"-Table. What is the syntax for that? ...

How I can update a Linq-object with a DetailsView?

Hi Chaps, I use a DeatialsView with AutoGeberateColoums for my user administration. Here my start code: Business.UserHandling uh = new Business.UserHandling(); DAL.Benutzer user = uh.GetSingleUser(BenutzerID_Int); List<DAL.Benutzer> listUser = new List<DAL.Benutzer>(); listUser.Add(user); Detail...