How can I get a new distinct list from an existing list using LINQ? This is what I have so far and it is not distinct but does give me a new list.
Dim tmpQryColumn = (From a In _allAudits Select New CheckBoxListItem With {.Id = a.AuditColumn, .Name = a.AuditColumn} ).Distinct() _columnList = New List(Of CheckBoxListItem)(tmpQryColumn)
Supposing the referenced List below contains 2 elements: Dim Countries = From c In List _ Select New With { .Country = c.Country, .CountryID = c.CountryID }
I have a datatable which has been dynamically generated from FoxPro tables using a UNION Select statement. e.g.SELECT * FROM x UNION SELECT * FROM y UNION SELECT * FROM Z ORDER By v_alue1This produces a datatable with about 100 rows, each containing many fields, one of which is c_olor. From this datatable, I would like to select the distinct colors and then output in a dropdown.I have a public class Color which just has one property which I can then use as the DataTextField and DataValueField for the dropdownlist
Public Class Color Private _c_olor As String Public Property c_olor() As String
I load a list from a database like the example below. The class has more properties that the database table holds so when I load the list from the DB, there are Null values for certain properties of each item in the list. When I try List = List.Distinct.ToList, it never works (when null values are present).
I'm having issues with returning a list of strings of the .Value of a Linq query:
Dim details = <Details> <Vector size="5"> <Item>Syntactic Structures</Item> <Item>Introduction</Item> <Item>The Independence of Grammar</Item>
[Code]...
Is correct in that it returns the list of XElements I want (items 1 - 4, base 0), but I really just need a list of strings for the .Value of those XElements. Maybe I'm just dense here, but anything I've tried in the chapterTitles query isn't working (appending with .ToList.ToString, etc.). details.<Vector>.<Item>.Skip(1).Take(4).Value just returns the first XElement's value.
I am having so trouble with the ToUpper() procedure with strings. I am using LINQ to find unique values in a list of objects. In that whole process I set the values to compare to all lowercase in order to get a proper list. My goal is to populate a dropdown list with the values. I'm attempting to set the first letter of of the string to uppercase and keep the rest lowercase however the toUpper() procedure is not working?
Private Function FixCase(ByVal strIn) As String Dim strOutput As String Dim intStringLength As Integer = strIn.Length - 1 strOutput = strIn.Substring(0, 1)
When the user has typed in some information I would like to output possible matches in a descending order, so if someone types in a full first name and a full surname, it should be listed above a result where just the surname matches.I've done something similar in SQL before which worked perfectly, but this time I'd like to do it in LINQ.
Firstname, Surname, City, Country as string variables. Dim DataEnum As IEnumerable(Of frmTelephone.clsPerson) = alPerson.OfType(Of frmTelephone.clsPerson)()
I can't quite figure out why this Linq Statement isn't working as i would expect:
[Code]....
I would assume that this would create a new collection of anonymous types, that would be distinct. Instead it creates a collection the size of the "ThisParentCollection" with duplicate "MyAnonymousType" in it (duplicate id's).
I have a very interesting LINQ question. I have a document, that I am trying to filter results on, but to filter, I am matching on a REGEX result from one element of the XML. I have the following, working LINQ to XML to get the individual data that I'm looking for.
I have a single columned datatable inside a single tabled dataset.I just want to convert this dataset to distinct rows. Here is my code, it gives compile error '.' expected.
Dim query = _ From email In ds.Tables(0) _ Select email.Field<string>("Email").Distinct()
EDIT: I changed to (Of String) and it works... BUT NOW 'query' is an ienumerable collection of characters... not a datatable... so how do I convert back easily without manually doing a loop?
I'm trying to LINQ two tables based on a dynamic key. User can change key via a combo box. Key may be money, string, double, int, etc. Currently I'm getting the data just fine, but without filtering out the doubles. I can filter the double in VB, but it's slooooow. I'd like to do it in the LINQ query right out of the gate.
[Code]...
"Range variable name can be inferred only from a simple or qualified name with no arguments."
I'm trying to LINQ two tables based on a dynamic key. User can change key via a combo box. Key may be money, string, double, int, etc. Currently I'm getting the data just fine, but without filtering out the doubles. I can filter the double in VB, but it's slooooow. I'd like to do it in the LINQ query right out of the gate.
I have to perform the following SQL query: select answer_nbr, count(distinct user_nbr) from tpoll_answer where poll_nbr = 16 group by answer_nbr The LINQ to SQL query
I have a stored procedure (I cannot edit) that I am calling via linq.
The stored procedure returns values (more complex but important data below):
Customer Stock Item Date Price Priority Qty -------------------------------------------------------- CUST1 TAP 01-04-2012 £30 30 1 - 30 CUST1 TAP 05-04-2012 £33 30 1 - 30 CUST1 TAP 01-04-2012 £29 20 31 - 99 CUST1 TAP 01-04-2012 £28 10 1 - 30
I am trying to limit this list to rows which have unique Dates and unique quantities in LINQ. I want to remove items with the HIGHER priority leaving rows with unique dates and qty's.
I have tried several group by's using Max and order by's but have not been able to get a result.
Is there any way to do this via linq?
EDIT:
Managed to convert brad-rem's answer into VB.net.
Syntax below if anyone needs it:
returnlist = (From p In returnlist Order By p.Qty Ascending, p.Priority Group By AllGrp = p.Date, p.Qty Into g = Group Select g.First).ToList
The following data is created by joining two sql tables together:I would like to group together distinct rows of DateStamp/UserName/ StudentName/ InstructorName/TableName/PrimaryKey (I'll call this 'group records') and then group under these ColumnName/PreviousValue/NewValue (I'll call this 'subgroup records')The end result would be that I could iterate through the 'group records' - there would be 5. In each 'group record', I could then iterate through the 'subgroup records'. The 5 groups would contain 3, 2, 5, 2 and 1 subgroup records respectively.What would be the syntax to create a query to do this? Ideally this would be in a vb.net linq syntax.
I am trying to get distinct rows based on multiple columns (attribute1_name, attribute2_name) and get datarows from datatable using Linq-to-Dataset.[code]How to do thin Linq-to-dataset?
I have a DataTable with about 64 columns, including "UserAnswer", "CorrectAnswer", and "QID_Lookup". I am building a LINQ that will select all the rows that have a correct answer (user answer matches correct answer), but I only want to select rows that have distinct "QID_Lookup".
[Code]...
The problem is that the result set includes duplicate QID_Lookup values. How can I include only distinct QID_Lookup values? keep in mind that there are 64 columns, so if I can avoid it, I wouldn't want to list each column individually for selection.
I have an EnumerableRowCollection that looks like the following: VendorCode | GroupType | Variance 01165 G .16 01165 G .16 01165 CH .16 01165 CH .18 07754 G .25 07754 G .25 07754 G .39
Essentially, this is a massive list of vendor codes, their groups, and price variances. I need to compose a query that will create a distinct list vendor codes and group types. The catch, however, is that I need to evaluate all of the variances associated with that particular VendorCode/GroupType to see if they are all the same - it they are not, I need to return some way of signifying that the group has a "custom" variance, otherwise it needs to return the value (ie: if they are all .16, then return .16, if there are multiple values, return "custom")
The result would look like this, based off of the list I showed above. VendorCode | GroupType | Variance 01165 G .16 01165 CH custom 07754 G custom
I have no trouble getting a distinct list of VendorCode/GroupType - this is what I have so far: Dim distinctList = From q In query Select q.VendorCode, q.GroupType, (evaluated q.Variance here?) Distinct (where "query" is an EnumerableRowCollection(Of (anonymous type))) I'm at a loss, though, on how to evaluate the variance property to get the result that I need?
My particular example is fairly complex but I think the concept would apply equally to something like a logging system so I'll use that instead for ease of explanation. It's a ficticious example, please don't harp on or agonise over what is achitectually, programatically or morally wrong with the example itself
[Code]...
I don't want to 'cheat' and resort to a long-winded way of doing it when performance isn't critical here and I'm moderately confident it can be done in a single LINQ statement.