linq

How can I write my SQL query in LINQ?

I have a table that looks like this. The query needs to return the last date entry for each location. How would I write this in SQL and LINQ? Id Location Salary Date 1 Los Angeles $1500 Jan-05-1999 2 San Diego $250 Jan-07-1999 3 Los Angeles $300 Jan-08-1999 4 Boston $700 Jan-08-1999 ...

How can I add a new property in an already existing xml file?

Hi, I am working on an application that parses a .csproj file. It needs to add an additional value to the <NoWarn> property if it exists. In the event that the property does not exist I want the application to add this property with its value to the specified parent node. How can I achieve this? I am using LINQ-to-XML to parse the proj...

Pivot against a SQL stored procedure (or LINQ)

I am trying to create a Stored procedure (or query expression) that Pivots on a grouping ID. After looking at the examples here and elsewhere I have failed to get my pivot statements to work in a stored procedure, and I am looking my help. Also, if this could be done with LINQ on a LIST that would be a solution for me also. theID ...

LINQ Database

I have a system that supports multiple products. Each product has its own database with the same exact schema. When I pass in the connection string as a parameter to my Data Context constructor it always uses the default database listed in the connection string, or the default database of the user connecting if I do not provide an Initi...

Best way to update in Linq To SQL

Hello All, I have several entity classes that I use for parsing fixed width text files as well as utilizing Linq to SQL. I use these classes to parse data from said text files, and compare to data in the database. One of these entities has a lot of properties, and I don't want to waste time setting each individual property on the Linq r...

How to create an aggregate Atom feed from two Atom feeds using LINQ to XML

Just took a stab at creating an aggregate feed - from two separate Atom feeds - sorted descending by published date... UPDATE: Thanks to Martin Honnen (MVP) over at http://social.msdn.microsoft.com/Forums/en-US/categories/ - combined with a safe XElement.Load(url) helper (and iterator block)... I think the code below is a pretty good a...

Restrict LINQ Subquery when databound to a grid

I want to limit the number of child elements I get back. In this example Order.CustomerID "VINET" has 3 Order Details. I only want to see the record that has a unit price of 14. I do NOT want to see the Order Details where the unit price equals 9.8 or 43.8 In the end I want to do this in a dynamic where query or with a predicate, but...

Enumerable.Except Problem

Can someone explain why this doesn't work like I think it should. double[] numbers1 = { 2.0, 2.1, 2.2, 2.3, 2.3, 2.3, 2.4, 2.5 }; double[] numbers2 = { 2.2 }; IEnumerable<double> onlyInFirstSet = numbers1.Except(numbers2); foreach (double number in onlyInFirstSet) Console.WriteLine(number); /* This code produces the following ou...

LINQ to read XML (C#)

I got this XML file <root> <level1 name="A"> <level2 name="A1" /> <level2 name="A2" /> </level1> <level1 name="B"> <level2 name="B1" /> <level2 name="B2" /> </level1> <level1 name="C" /> </root> Could someone give me a C# code using LINQ, the simplest way to print this result: (Note the extra space if it is a level2 node)...

A range of objects from a list

I am having a List of say 100 objects. Now I want to get object from 50th to 60th. How can I do it. I except there will be a simple linq query or lambda expression that I can use. But I am very new to LINQ and could not find a way searching. ...

Order by with Collate clause | Entity Framework

I don't want to use array sorting on the web server it should be done on SQL server. Microsoft does not support query(in EF) like this: SELECT * FROM [Table_1] ORDER BY [Table_1].field COLLATE SQL_SwedishStd_Pref_Cp1_CI_AS Any ideas? Thank you in advice... ...

How can I search for an element in a treeview with linq?

I'm searching for a linq-to-objects way to get a TreeViewItem from a treeView. I want to do something like this: var node = from TreeViewItem childs in tree.Items where ((int) childs.Tag) == 1000 select childs; string tag = ((TreeViewItem)node).Tag.ToString(); Then I want to append children t...

Type Constraint on foreach using LINQ extensions.

I have seen a method somewhere here on SO to restrict items returned from a foreach loop to a certain type, using, if I remember correctly, LINQ extensions on IEnumerable and a lamda for the type check. I can't find it again, can anyone suggest how this was achieved? ...

Linq/nHibernate alternatives/equivalents?

I heard about a very nice Linq/NHibernate alternative O-R bridge, but darnit can't remember its name. I remember their site featured very instructive screencap video tuts by the developers and the tool can be used as a replacement for Linq. Help! Any pointers? ...

How LINQ works internally?

Hi everyone... I love to use LINQ on .net, but I wonder to know how does that works internally? Does anyone know that? Thks. ...

How to replace xml content in conditionally selected elements using linq (VB 2008)

I'm working on a .NET application (VB 2008) that gets all of its data from a web-based Django application. I'm using Linq-to-XML and Linq-to-objects in the app. One API call is giving me XML data in the following format that I am loading into an XDocument. <django-objects version="1.0"> <object pk="1" model="app.person"> <...

Retrieving Property name from lambda expression

Is there a better way to get the Property name when passed in via a lambda expression? Here is what i currently have. eg. GetSortingInfo<User>(u => u.UserId); It worked by casting it as a memberexpression only when the property was a string. because not all properties are strings i had to use object but then it would return a unary...

LINQ statement where result count is used in expression's condition

O' LINQ-fu masters, please help. I have a requirement where I have to add items into a List(Of T) (let's call it Target) from an IEnumerable(Of T) (let's call it Source) using Target.AddRange() in VB.NET. Target.AddRange(Source.TakeWhie(Function(X, Index) ?)) The ? part is a tricky condition that is something like: As long as the as ...

Problem with 'where()' method.

Referring to my question on filtering ('constraining') types in a foreach loop, I am trying the first method in Charlie Flowers's answer, using the .Where method on the collection, but the compiler can't find .Where on the System.Web.UI.ControlCollection class. This is derived from IEnumerable, so what's the problem here? foreach (var ...

how to assign default value to timestamp datatype in c#?

i want to do above. i have an object of table in c#. ...