Linq to Datarow; Select multiple columns individually?

I am basically trying to reproduce the following mssql query as LINQ

SELECT DISTINCT [TABLENAME], [COLUMNNAME] FROM [DATATABLE]

nearest i got

Dim query = (From row As DataRow In ds.Tables("DATATABLE").Rows _
                  Select row("COLUMNNAME") ,row("TABLENAME").Distinct

when i do above i get error

The name of a range variable can only be inferred from a simple or qualified name with no arguments.

I was kind of expecting him to return a collection, which I could then execute and complete the actions for each entry. perhaps a datarow collection?

Like the full LINQ newb, I'm not sure what I am missing. I tried the options on

Select new with { row("COLUMNNAME") ,row("TABLENAME")}

and get:

A member name of an anonymous type can only be inferred from a simple or qualified name with no arguments.

to get around this i tried

 Dim query = From r In ds.Tables("DATATABLE").AsEnumerable _
        Select New String(1) {r("TABLENAME"), r("COLUMNNAME")} Distinct

however, it does not appear that he is doing the clear thing correctly.

Also, does anyone know any good books / resources to speak fluently?

+3
4

, . .

, ?

,

Dim comp As StringArrayComparer = New StringArrayComparer
Dim query = (From r In ds.Tables("DATATABLE").AsEnumerable _
        Select New String(1) {r("TABLENAME"), r("COLUMNNAME")}).Distinct(comp)

(2 ),

Public Class StringArrayComparer
    Implements IEqualityComparer(Of String())

    Public Shadows Function Equals(ByVal x() As String, ByVal y() As String) As Boolean Implements System.Collections.Generic.IEqualityComparer(Of String()).Equals

        Dim retVal As Boolean = True

        For i As Integer = 0 To x.Length - 1
            If x(i) = y(i) And retVal Then
                retVal = True

            Else
                retVal = False
            End If

        Next

        Return retVal

    End Function

    Public Shadows Function GetHashCode(ByVal obj() As String) As Integer Implements System.Collections.Generic.IEqualityComparer(Of String()).GetHashCode

    End Function
End Class
+1

LINQ , dt.AsEnumberable, DataRow IEnumerable.

Dim query = From row As DataRow In ds.Tables("DATATABLE").AsEnumerable _
              Select row("COLUMNNAME") ,row("TABLENAME")

, row("COLUMNNAME").ToString() .. IEnumerable 2 ; , ? ; , .

Dim query = From row As DataRow In ds.Tables("DATATABLE").AsEnumerable _
              Select .ColumnName = row("COLUMNNAME"), .TableName = row("TABLENAME")

, sql-, ADO , , .

:

, Linq-to-SQL ( Linq-to-object) LINQ-to-Dataset - . , LINQ , .

LINQ--Dataset

:

1 datatable , , .., . , , :

2 linq dt.AsEnumerable, IEnumerable datarow.

Linq-to-dataset (A) Linq-to-SQL, ADO.NET, ( B), , LINQ (-to-object) // , 6 . . ado sql ( , ), LINQ

LINQ--SQL

- , , . LINQ-To-SQL :

1 , db, Visual Studio, , .
 2 linq, db, .

.NET LINQ SQL , , .

:

, . , :
 LINQ-to-SQL
 LINQ-to-Dataset

LINQ LINQ , , (). ! , . . LINQ ​​, . .NET , , LINQ, .

+6

, LINQ IEnumerables, :

Dim query = (From row As DataRow In ds.Tables("DATATABLE").Rows _
              Select row!COLUMNNAME, row!TABLENAME).Distinct

VB bang (!) " ..." , , .Distinct (IEnumerable ) , Distinct .

LINQ IEnumerable , DataRow,

For Each result In query
   Msgbox(result.TABLENAME & "." & result.COLUMNNAME)
Next

, - ...

0

Source: https://habr.com/ru/post/1741478/


All Articles