linq

Linq query has an implicit cast error for DataGridViewRow when option strict is enabled

I have a DataGridView that is bound to a list of objects called "BaseChange". The BaseChange objects are made up of 4 properties... ChangeType ChangeStatus ChangeDescription LastChangeDate The datagridview has columns for all 4 values as well as a 5th (a checkbox column called "colIsSelected"). There is no problem binding the list to...

linq subquery returning null

I have an odd linq subquery issue. Given the following data structure: Parents Children ------- -------- Id Id ParentId Location HasFoo (obviously this is not the real structure, but it's close enough for this example) I'm able to run this ...

LINQ Skip(0) vs Skip(n), return inconsistent sort expression

Hello, When calling the Skip() method with a starting index other than 0, the method automatically appends additional columns 'in addition to' the existing order-by column. These additional order-by columns consist of the remaining columns that are not in the sort expression. Great job for LINQ to handle this automatically for us as i...

Linq to objects nested group-by

I have this query working but it is not returning back exactly what I am looking for. I have a collection of: List<TransactionRecord> transactionLog; TransactionRecord simplified looks something like this: class TransactionRecord { public string txSetComments; public string BatchComments; public string TargetComments; pu...

Left join in Linq?

There are a lot of questions on SO already about Left joins in Linq, and the ones I've looked at all use the join keyword to achieve the desired end. This does not make sense to me. Let's say I have the tables Customer and Invoice, linked by a foreign key CustomerID on Invoice. Now I want to run a report containing customer info, plus...

Code equivalent to the 'let' keyword in chained LINQ extension method calls

Using the C# compilers query comprehension features, you can write code like: var names = new string[] { "Dog", "Cat", "Giraffe", "Monkey", "Tortoise" }; var result = from animalName in names let nameLength = animalName.Length where nameLength > 3 orderby nameLength select animalName; In the query expression above,...

Linq Nested Grouping

I've a large table of Items and I need to organize them by Category, then by Year and then by Month. Item has CategoryID and Dated properties. I got this far: Dim Items = From Item In DB.Items _ Group By CategoryID = Item.CategoryID _ Into Categories = Group _ Order By CategoryID But where I put the: ...

Performance difference with MemberInit Expression

I am working a similar problem as Question 222511 I do need to use the MemberInit Expression so I can just add them to the constructor... I am trying to implement John Skeet's answer but I am running into a big performance difference. Here is some of the code: // Method A: // This work good, is fast and returns an un-executed query... D...

How do you left join in Linq if there is more than one field in the join?

I asked a question earlier about why left joins in Linq can't use defined relationships; to date I haven't got a satisfactory response. Now, on a parallel track, I've accepted that I need to use the join keyword as if there were no relationship defined between my objects, and I'm trying to work out how to express my query in Linq. Trou...

Handling CRUD Operations for a Linq to SQL View

I am running into a problem where my CRUD operations on an entity sourced from an SQL View is not calling the generated methods for said operations. Example: I press "Delete" in a ListView on an item, connected to a LinqDataSource. It throws an error saying that it cannot perform the operation because it affects multiple base tables. T...

LINQ and group by data nested within a structure

I have a structure that roughly looks like this: List<ProductLine> -> ID Name ... List<LineOfBusiness> -> ID Name ... List<Watchlist> -> ID ...

Simple LINQ query

I have a collection like this List<int> {1,15,17,8,3}; how to get a flat string like "1-15-17-8-3" through LINQ query? thank you ...

How do I connect webapp VB/LINQ to a MySQL database server on a Linux

I have a programmer who is using VB and LINQ; and I have a MySQL database that is running on a linux server. My programmer tells me that: he cannot connect to the MySQL database via LINQ if he was able to connect then it would require all sorts of rewriting I don't know anything about LINQ but I thought it was an ORM. As such, any D...

Does Linq cache results of multiple Froms?

Suppose we got a code like this: IEnumerable<Foo> A = meh(); IEnumerable<Foo> B = meh(); var x = from a in A from b in B select new {a, b}; Let's also assume that meh returns an IEnumerable which performs a lot of expensive calculations when iterated over. Of course, we can simply cache the calculated results manually by ...

linq to xml access data based on field attribute

I have some xml like this: <Data> <Rows> <Row> <Field Name="title">Mr</Field> <Field Name="surname">Doe</Field> <Row> <Rows> <Data> using linq how can I get the value contained in the field element where the attribute is surname thanks ...

Using LINQ with classes implementing non-generic ICollection

I wanted to run a LINQ query against a MatchCollection object but found this wasn't possible as it doesn't implement ICollection<T>, just ICollection. What is the best option for using LINQ with non-generic collections, both in terms of code conciseness but also performance and memory usage? (If interested, here is the non-LINQuified c...

Extracting generic Linq queries

I'd like to use Linq to SQL in my windows form application. The data in the local database is fetched from the Web Service or created locally. If an entity was fetched from the Web Service it has ExternalId set up I frequently need to use code as below to fetch objects by theirs ExternalId: var user = (from u in db.User ...

Generating indexes in Linq

I'd like to use Linq to XML to output a sorted list each element should contain a value and its index on that list. In other words I would like to do something like this (xml stuff was striped out): var Sample = new[] { "4", "3", "2", "1" }.AsQueryable(); var r = (from o in Sample orderby o select new {obj=o, idx=?}); I'm not sure ...

multiple grouping, inner joning in Linq

I am trying to translate this into Linq and cannot figure it out: SELECT CustomerOrder.ShipState, MONTH(OrderFulfillment.OrderDate) AS Mnth, YEAR(OrderFulfillment.OrderDate) AS Yer, SUM(OrderFulfillment.Tax) AS TotalTax FROM OrderFulfillment INNER JOIN CustomerOrder ONOrderFulfillment.OrderID =CustomerOrder.Order...

Efficient way to get first missing element in ordered sequence?

I have an ordered sequence like {1, 3, 5, 6, 8, 9} I want to get first missing element(2 in the example) or max() if sequence contains no missing elements. Now I'm doing it like this: public static int GetRegisterNumber<T>(this IQueryable<T> enumerable, Func<T, bool> whereFunc, Func<T, int?> selectFunc) { var regNums = enumerable.Or...