I have a simple text file containing some CSV with the following structure:
@Parent1_Field1, Parent1_Field2, Parent1_Field3
Child1_Field1, Child1_Field2
Child2_Field1, Child2_Field2
...etc.
@Parent2_Field1, Parent2_Field2, Parent2_Field3
Child1_Field1, Child1_Field2
Child2_Field1, Child2_Field2
...etc.
'@' indicates a parent object ...
Suppose I have
var input = new int[] { 0, 1, 2, 3, 4, 5 };
How do I get them grouped into pairs?
var output = new int[][] { new int[] { 0, 1 }, new int[] { 2, 3 }, new int[] { 4, 5 } };
Preferably using LINQ
...
I wrote this:
public static class EnumerableExtensions
{
public static int IndexOf<T>(this IEnumerable<T> obj, T value)
{
return obj
.Select((a, i) => (a.Equals(value)) ? i : -1)
.Max();
}
public static int IndexOf<T>(this IEnumerable<T> obj, T value
, IEqualityComparer<T> comp...
I have 3 listviews in a wpf grid column, one each for customers, products, and vendors. They each get data from LINQs to separate SS2005 queries in the same db. The lists are populated when a user enters text in a textbox. The LINQ query code uses as startswith() function that reads the user entry and returns a smaller list to the listvi...
Here's the scenario:
Given a List of Outputs each associated with an integer based GroupNumber. For each distinct GroupNumber within the List of Outputs starting with the lowest GroupNumber (1). Cycle through that distinct group number set and execute a validation method.
Basically, starting from the lowest to highest group numbe...
I am trying to create a simple Silverlight application that calls an ATOM feed and displays the article title and submit date. I found this very easy to do with RSS feeds and LINQ but I am stuck trying to do the same with an ATOM feed. The code below produces no errors but it also produced no results! What am I missing?
Source ATOM f...
I'm using a generic list. For example (with some properties):
public class randomList
{
public string propertyA { get; set; }
public string propertyB { get; set; }
public string propertyC { get; set; }
}
So on my retrieving query I used to write the following:
_grouppedResto.Select((value, index) => new { i...
Hi
I get the followwing direcories by calling GetDirectories()
c:\app\20090331\
c:\app\20090430\
c:\app\20090531\
c:\app\20090630\
c:\app\20090731\
c:\app\20090831\
I want to the directories between 20090531 and 20090731, How can I do it by Linq?
Thanks!
...
Linq is a very useful feature of C# 3.0 which has been out for a while now. Unfortunately, a number of the developers at the company I work for do not know much about Linq and how it can benefit them. As such, I've been given the opportunity to present an information session about Linq.
What I'm trying to figure out is, what is the best...
I want to group by the WorkGroup.GroupId property on the class
public class Employee
{
public int EmployeeID {get; set;}
public Group WorkGroup {get; set;}
}
However I need to output the group name property (Which could have duplicates but will be identical between the same groupid)
Something like (this of course does not work):...
I have a scenario where I have custom configured column names, associated operators like < > = between etc. and then a value associated.
I'm trying to determine if it is possible to build up a LINQ query with a dynamic (string) where clause?
I've noticed the Predicate.OR Preditcate.AND stuff, but that is not quite what I'm talking abou...
In database, I have a LastEditTime column of type datetime. I used this to track last row update/insert time. Linq throws exception claiming that it can not insert null at that column.
Naturally, since LastEditTime column is NOT NULL, an exception is expected. My hand generated query inserts getutcdate(). How can I ask Linq to do simila...
If I have a Publisher table that has many Books, and each Book can have many Authors, how do I get a list of distinct Authors for a Publisher? In SQL you would just join all the tables, select the Author, and use SELECT DISTINCT. Using LINQ I end up with an IEnumerable(Of EntitySet(of Author)):
Dim temp = From p in Publishers Select (Fr...
Example:
myEnumerable.Select(a => ThisMethodMayThrowExceptions(a));
How to make it work even if it throws exceptions? Like a try catch block with a default value case an exceptions is thrown...
...
Hi,
We just created a new field in a database table, and so deleted, and re-inserted the table in the LINQ Class. The new database field appears in the LINQ Class in the diagram. However, when we're using the field, we get an error that says the table does not contain a definition for the field.
Any ideas on how we can solve this? Than...
I have a LINQ query which returns all the values inside a Dictionary, conditional upon something:
var apps =
from entry in shape.Decorators
where entry.Value == DecoratorLayoutStyle.App
select entry.Key;
shape.Decorators is a
Dictionary<Shape, DecoratorLayoutStyle>
Is there something terser, and/or can I use a combination of lambd...
I have been using Linq to XML for a few hours and while it seems lovely and powerful when it comes to loops and complex selections, it doesn't seem so good for situations where I just want to select a single node value which XPath seems to be good at.
I may be missing something obvious here but is there a way to use XPath and Linq to XM...
I have two entities in Linq to Sql setup as a Parent/Child relationship (Parent can have many Children). I have an existing parent record and trying to create new child records to be "added" to the parent. Let's use the familiar Order and OrderDetails model for explanation.
I am trying a bunch of things to add my "child" to the parent...
Hi, I am using SQL Server 2005 in a project. I have to decide about datalayer. I would like to use LINQ in my project. I saw SubSonic 3 supporting LINQ and I also have option for LINQ to SQL, because i can have typed lists from LINQ to SQL.
I am wondering what is different between LINQ to SQL and Subsoinc 3 LINQ, Which is beneficial?
T...
How can I return first 100 records using Linq?
I have a table with 40million records.
This code works, but it's slow, because will return all values before filter:
var values = (from e in dataContext.table_sample
where e.x == 1
select e)
.Take(100);
Is there a way to return filtered? Like T-S...