linq

Convert a LINQ Query Resultset to a DataTable

How can i write this query with LINQ to a FoxPro database? SELECT count(*) FROM Table group by item1 I wrote it as below, but it doesn't work Dim Query Dim dt As New DataTable Dim da = New Odbc.OdbcDataAdapter("SELECT * FROM table1",connection) da.Fill(dt) Query = (From row In dt.AsEnumerable Select row_ Group By item1 ...

LINQ Select certain cell in DataGridView depending on other cell in row

I am brand spanking new to LINQ and am trying to use it in my current hobby project. I have a datagridview where the first cell of each row is a datagridviewcheckbox, and the 4th cell is a string. If the checkbox is checked, I need to add the 4th cell's value to a list. At first I tried: var selectedID = from c in multiContactLookup.S...

Casting the results of linq-to-sql

Working with interfaces, we commonly have a var or an IQueryable that is going to return a set of data objects that we will then cast to the interface and return as a List or IList, like this: var items = from t in SomeTable where t.condition == true select; return items.ToList( ).Cast<SomeInterface>( ).ToList( ); NOTE: items.Cast...

What is bltoolkit's BLTgen tool and how it should be used?

I guess it is something like sgen.exe which generates some serialization classes in separate assembly. Is that it? Should generated assembly be referenced? If so, by which project? I have noticed that some LINQ queries are very slow, when executed for first time. Maybe bltgen tool can help? I'll start a bltoolkit blog when I find all t...

Multiple Selection in ForEach Extension Method

Is it possible to select multiple entiies in ForEach Extension Method? (i.e) partial code is given DataTableA.AsEnumerable().ToList(). ForEach(x=> { x.SetField<string>("Name","Jon Skeet"), x.SetField<string>("msg","welcome") }); when i apply multiple selection in ForEach x=> { x.SetField<string>("Na...

Possible to update a row without pulling down and updating every column?

For examples sake, lets say I have a table containing these columns ID (primary key, auto increment) FirstName (32 characters) LastName (32 characters) Picture (binary JPEG data containing on average 10k of data) Using SubSonic and/or LINQ how can I update only the FirstName column of a record and not try to get the Picture column or...

Linq Contains method for a object

I have a object User and it is the following class: public class User { public int ID { get; set; } public string Name { get; set; } } And I have a IEnumerable<User> I want to find out if one specific user exists in IEnumerable<User>, comparing the user by it's ID. An example: IList<User> users = GetUsers(); // 1, 2, 3 ...

Complex Linq.Dynamic queries

I am trying to figure out how to create some dynamic queries. I have looked at Linq.Dyanmic and it is missing some things that I think I may need. My goal is to essential flatten the relational database, this is for creating searches on the fly by the user, into one object with properties from many different tables/entities. Example: ...

Resolving method overload among LINQ query methods

So, the context of this question is pretty specific, but I think there is a general C# question struggling to get out. :) I have an ASP.NET Web Forms page with a GridView control bound to an ObjectDataSource. The data source control is hooked to a data access class that, in turn, uses LINQ to query Entity Framework v4. The methods on t...

Creating a string from a lambda expression

I have functions that take SQL where clauses, and I'm wondering if there's a way to make them all strongly typed. Is there a way to take a lambda expression like a => a.AgencyID == id and convert it to a string where clause? Like "AgencyID = 'idValue'"? Thanks! ...

How do I fix my linq query

Here's the sample XML <?xml version="1.0" encoding="utf-8" ?> <Instructions> <Instruction> <Brand>Brand1</Brand> <Text> this is text for Brand1 </Text> </Instruction> <Instruction> <Brand>Brand2</Brand> <Text> Brand2 text is slightly different </Text> </Instruction> <Instruction> <Brand>...

Search Keywords using LINQ

If I have a text field that contains say a title and i have a list of keywords, how can i search the title checking for (n) numbers of keywords in the title? So if my title is "Baking a chicken, bacon and leek pie" and the user searches for "chicken bacon turnip" i'd like to return the above recipe. essentially i'd like to say that if ...

LINQ: "Group Join" functionality joining three tables

I've searched previous questions and can't seem to find what I'm looking for, so please excuse the n00b LINQ question... I'm working on becoming familiar with LINQ, and getting my head around the syntax and usage. In my exercises, I put together the following query: Dim r2 = From cust In cData.Customers _ Group Jo...

How to convert Foreach loop to Linq (in datagridview)

foreach (GridViewRow row in gridView.Rows) { // Access the CheckBox CheckBox cb = (CheckBox)row.FindControl("SuburbSelector"); if (cb.Checked) { //do something; } } I tried the following and got error Linq: var Str = SuburbGridView.Rows.Cast<GridViewRow>().Where(r=>(CheckBox)r.FindControl("SuburbSelector")==...

IList<T> does not have "where"

In a specific project at my work, I have a method that returns IList. But this interface does not contain where, or FindAll filters. However, when I open a new project, IList contains all. What is the difference? ...

How to remove substring from all strings in a list in C# using LINQ

I have a list of strings like "00000101000000110110000010010011", "11110001000000001000000010010011", I need to remove the first 4 characters from each string so the resulting list will be like "0101000000110110000010010011", "0001000000001000000010010011", Is there any way to do this using LINQ? ...

How to return rows with max value one column grouped by another column?

this is data id code status 1 1 5 2 1 6 3 2 8 4 2 9 5 2 12 6 3 15 7 3 19 8 3 13 what I need as a result is this: id code status 2 1 6 5 2 ...

Comparing Strings using LINQ in C#

I have two strings Like "0101000000110110000010010011" and "0101XXXXXXX101100000100100XX" it should compare each character and it should not consider if the character is X for the above two strings the result is true. now i'm using like Iterating through the length of the string and replacing thecorresponding character in firs...

LINQ to DataSet and xml help

I created a strongly-typed dataset in the dataset designer. The DataSet has a Table called FocusOffsetsTable and that table has four colums; SerialNumber, Filter, Wheel and Offset. I use the ReadXml() method of the DataSet class to load the strongly typed data from the xml file into the dataset. That seems to be working just fine. I am ...

Retreive all Children and their Children, recursive SQL

Consider the following rows in a database: Id | Parent __________________ 1 null 2 1 3 2 4 3 5 null 6 5 Each Id that has a null Parent is the "Owner"/"Super Parent". What would be the best approach, performance wise, to collect the parents and their children ? Shoul...