We have a form that allows a user to filter a list with by typing in a textbox. We need to filter the list based on two fields. The FundName and the CompanyName. When the form loads I put the initial LINQ to SQL results into a list so that for every subsequent action (filter) the database is not hit. This speeds things up significantly (...
I' trying to use a Linq query to find and set the selected value in a drop down list control.
Dim qry = From i In ddlOutcome.Items _
Where i.Text.Contains(value)
Dim selectedItem As ListItem = qry.First
ddlOutcome.SelectedValue = selectedItem.Value
Even though the documentation says that the DropDownList.Items collect...
I would like to be able to fusion an IEnumerable<IEnumerable<T>> into IEnumerable<T> (i.e. merge all individual collections into one). The Union operators only applies to two collections. Any idea?
...
Hi,
I am new to LINQ. I am trying to find the rows that does not exists in the second data table.
report_list and benchmark both type are : DataTable. Both these datatables are being populated using OleDbCommand,OleDbDataAdapter. I am getting an error "Specified cast is not valid." in foreach ... loop. I would appreciate your help.
...
I'm currently thinking about a repository pattern for my data objects, where multiple IQueryable<> instances can be registered as data sources. But it seems its not so easy to get it running :-)
Running a simple LinQ Query with Linq to entities and linq to objects doesnt work. Do you think this is in general possible? Maybe the only sol...
Update - for those of a facetious frame of mind, you can assume that Aggregate still produces the normal result whatever function is passed to it, including in the case being optimized.
I wrote this program to build a long string of integers from 0 to 19999 separate by commas.
using System;
using System.Linq;
using System.Diagnostics;
...
Something very basic seems to be escaping me.
Dim foo As New Dictionary(Of String, String)
foo.Add("key", Nothing)
foo.Add("key2", "something")
I wish to get a IDictiorany(Of String, String) back, with only elements that have a non empty value. I thought this would do it:
foo.Where(Function(x) Not String.IsNullOrEmpty(x.Value))
Bu...
Hi All,
Given a DataSet, I'm left joining DataTables[1-n] onto DataTable[0]. I have created a method with a signature as follows:
public DataTable LeftJoin(DataSet ds, params JoinKey[] JoinKey)
Notes:
The return type is a DataTable, which is the resulting left join.
DataSet ds is a collection of DataTables for joining.
JoinKey is ...
There was a library of dynamic Linq extensions methods released as a sample with VS2008. I'd like to extend it with a Join method. The code below fails with a parameter miss match exception at run time. Can anyone find the problem?
public static IQueryable Join(this IQueryable outer, IEnumerable inner,
string outerSelector, string in...
I've got a list of People that are return from an external app and I'm creating an exculsion lists in my local app to give me the option of manually removing people from the list.
I have a composite key which I have created that is common to both and I want to find an efficient way of removing people from my List using my List
e.g
...
Is there an equivalent of a SQL IN statement in LINQ to objects?
...
Hi folks,
i have an IList<Animals> farmAnimals;
this list has three types,
Cows
Sheep
Chickens
how can i remove all the Chickens from the list using a lambda query or linq-to-objects so i have a separate list of chickens and the original list now only has cows and sheep.
Do i have to make three lists (the original + 2 new ones, fi...
Hi,
I am getting a little confused and need some help please. Take these two classes
public class Comment
{
public string Message {get; set;}
public DateTime Created {get; set;}
}
public class Post
{
public int PostId {get; set;}
public string Content {get; set;}
public IList<Comment> Comments {get; set;}
}
I ...
A very simple ?: operator in C#, combined with a simple array and LINQ (to Objects) call to Reverse() is apparently enough to cause the exception "System.Security.VerificationException: Operation could destabilize the runtime." when run on an ASP.NET web site running with "High" trust (note that "Full" is the default)
Here is the code, ...
I have the following class objects:
public class VacancyCategory
{
public int ID { get; set; }
public string Text { get; set; }
public IList<VacancySubCategory> SubCategories { get; set; }
}
public class VacancySubCategory
{
public int ID { get; set; }
public string Text { get; set; }
public VacancyCateg...
With LINQ, a lot of programming problems can be solved more easily - and in fewer lines of code.
What are some the best real-world LINQ-to-Objects queries that you've written?
(Best = simplicity & elegance compared to the C# 2.0 / imperative approach).
...
When using a SortedDictionary in Linq and iterating over the KeyValuePair it provides, can I be assured that a complex linq query will execute it in ascending order? Here's a brief, although a bit confusing example:
Random r = new Random();
//build 100 dictionaries and put them into a sorted dictionary
//with "priority" as the key and ...
I have a double[][] that I want to convert to a CSV string format (i.e. each row in a line, and row elements separated by commas). I wrote it like this:
public static string ToCSV(double[][] array)
{
return String.Join(Environment.NewLine,
Array.ConvertAll(array,
row => ...
I want to write an elegant linq query to handle the following SAMPLE object model:
class Category
{
public string Name { get; set; }
public IList<Product> Products { get; set;}
}
class Product
{
public string Title { get; set; }
public IList<Photo> Photos { get; set; }...
This feels like a completely basic question, but, for the life of me, I can't seem to work out an elegant solution.
Basically, I am doing a Linq Query creating a new object from the query. In the new object, I want to generate a auto-incremented number to allow me to keep a selection order for later use (named Iter in my example).
...