linq

Can someone explain this Linq Query?

I got this linq example from msdns 101 linq examples: public void Linq12() { int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var numsInPlace = numbers.Select((num, index) => new {Num = num, InPlace = (num == index)}); Console.WriteLine("Number: In-place?"); foreach (var n in numsInPlace) { Console.WriteL...

Fluent NHibernate HasManyToMany only works on first load

This is a weird one for me. I have a simple domain with 2 entities Company and Carrier. They have a m:m relation via another table. I set up my Fluent mappings as so public partial class Carrier { public virtual int ID { get; set; } public virtual string Name { get; set; } public virtual IList<Company> Companie...

Passing func from method parameter into a LINQ method (generic types)

In the signature of a method I specify a Func, like so: public void Method (Func<string, bool> func) In LINQ, which method (from IEnumerable) will let me pass in a Func from the method parameter to the LINQ query? The other issue is, my func can have any type parameter(s) so the Method from IEnumerable/LINQ must support generic type p...

C# LINQ query to select only first date in a month from List<DateTime>

I have a List which contains dates from June 1, 2009 to June 1, 2014. How would I query it in C# LINQ to select only the first date of each month? ...

C# loopless way to split string into multidimensional array or jagged array

Hi, How do I split a string into a multidimensional array or a jagged array without looping? I saw a code snippet where someone was doing so with a file stream and I can't figure out how to make it work for my string. My string is similar to 1:2;3:1;4:1 and can be split into ID:Qty. Here is the code I saw: string[][] lines = File.ReadA...

Linq Aggregate complex types into a string.

I've seen the simple example of the .net Aggregate function working like so: string[] words = { "one", "two", "three" }; var res = words.Aggregate((current, next) => current + ", " + next); Console.WriteLine(res); How could the 'Aggregate' function be used if you wish to aggregate more complex types? For example: a class with 2 proper...

What operators should have LINQ query expression support?

Of the 51 Standard Query Operators (of which only 42 are actually query operators), only 24 are directly supported by Visual Basic 9 and just 11 by C# 3: Query Expression Syntax for Standard Query Operators. In many cases, query syntax is arguably more readable than the equivalent method syntax, especially when transparent identifiers a...

Why didn't the LINQ designers stick with using the way sql is written today?

For example, why do you do this in LINQ var products = from p in Products select p.Name; when they could have done this: var products = select p.Name from Products p; Does the second offer some limitations in linq? Maybe the above examples are too simple to actually see why linq is written in one order and sql is wri...

C#: Linq style "For Each"

Possible Duplicate: Linq equivalent of foreach for IEnumerable Is there any linq style syntax for "For each" operations? For instance, add values based on one collection to another, already existing one: IEnumerable<int> someValues = new List<int>() { 1, 2, 3 }; IList<int> list = new List<int>(); someValues.ForEach(x => list....

How to generate a unique list of items from another list using LINQ in C#

I have a list of items like so {One,Two,Three,One,Four,One,Five,Two,One} and I need a query that takes that list and generates a list based on only unique items, so the list returned would be {One,Two,Three,Four,Five}. ...

LINQ to SQL Update (C#)

Hello all, This is the script of my table: CREATE TABLE ClientTypes ( type_id int PRIMARY KEY IDENTITY, type_name varchar(250) not null, type_applications_list text, dtIntro datetime DEFAULT(getdate()) ) And in ASP.net i'm trying to do this: protected void btnActualizar_Click(object sender, EventArgs e) { ...

Join Collection of Objects with LINQ to SQL

Is this even possible? It seems like I should be able to. This is my issue. I need to run a web service method from a 3rd party to get a collection of available items where I need the ID and a Status property. Then I have method using LINQ to SQL that retrieves the items that are current. What I need to do is retrieve the items that ar...

How do I get a list of integers that exist in one collection, but not in another of a different type using LINQ?

I have two different collections: List<int> IEnumerable<IDataRecord> The first contains a list of primary keys. The second contains data records. What I would like to do is determine which primary keys in the first collection do not exist in the second based on a given column name and return them as a new collection. For example, if ...

How do I modifiy this linq query using the lamdba operator?

I have the following linq query: var files = (from d in new DirectoryInfo(@"c:\program files").GetDirectories() where d.GetFiles().Count() > 10 where d.GetFiles().Count() < 100 select d ); However, as you can see above, I am calling d.GetFiles().C...

LINQ: dot notation equivalent for JOIN

Consider this LINQ expression written using query notation: List<Person> pr = (from p in db.Persons join e in db.PersonExceptions on p.ID equals e.PersonID where e.CreatedOn >= fromDate orderby e.CreatedOn descending select p) ...

How to get all records from thisa year onwards from LINQ to SQL model?

Can anyone tell me an efficient way of returning this. I have: var allPrices = site.Prices.AsQueryable(); I now want to query allPrices from current year onwards. Thanks ...

LINQ SELECT FIRST ROW

Hi, How can I select first row in a linq select statement without using foreach? I use foreach and then break; but it has to be a better way? I like to get the value in first row; plus check if no row is found. My problem is to get the value without foreach statement. What I do is to find a value in my DataTable and I know the row is...

"No data exists for the row/column" exception after using ToList

I have an extension method to convert a DbDataReader to an IEnumerable object: public static IEnumerable<IDataRecord> AsEnumerable(this DbDataReader reader) { while (reader.Read()) { yield return reader; } } In my application, I query the database like so: var records = context.Query("select WRKORDNBR from WRKORDER")....

Is it time to drop support for .NET 2.0 and move to .NET 3.5 ?

I provide a library that currently has .NET 2.0 as a pre-requisite. I'd like to go to .NET 3.5, to take advantage of LINQ, and Action delegates, and so on, but I don't want to strand too many people. Now that 4.0 is nearing release, is it time to move up to 3.5? The library works on the desktop and CF versions of the Framework. Does...

Any libraries available for doing LINQ over EAV pattern?

Does anyone know of any libraries which implement an abstraction in LINQ over the EAV (Entity Attribute Value) pattern? I have a large legacy EAV database and I'm trying to create a cleaner data access layer and the thought of using LINQ really appeals so I'm looking for any code I can use to jumpstart. ...