Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best way to handle cursors..?
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01562212
Message ID:
01562553
Vues:
49
>>There is nothing specific that I don't understand. Well that's not true. What I specifically don't understand is that it takes such an excrurciating long time to get it to work and that it replaces a dml (sql) that is widely used. Writing my first SQL inline in foxpro was a WOW experience. If there's anybody out there who was impressed by what he can do with LINQ, let him throw the first link. (hmm must not be the first one to put it like that.).
>
>Are you talking about Linq to Sql specifically or Linq in general (Linq to DataSet, Object, XML, Entities) ?

Basically I'm talking about LINQ in vb.net. I suspect that if you are up and running in C# this kind of construction does not look too unfamiliar, but for a vb programmer, this looks very exotic :
            Dim oDt As New DataTable
            oDt.Columns.Add("Sight", GetType(String))
            oDt.Columns.Add("Quality", GetType(String))
            oDt.Columns.Add("ValueBox", GetType(Double))
            oDt.Columns.Add("Yield", GetType(Double))
            oDt.Columns.Add("RoughStock", GetType(Double))
            oDt.Columns.Add("PolishedStock", GetType(Double))
            oDt.Columns.Add("InProduction", GetType(Double))
            oDt.Columns.Add("Overhead", GetType(Double))
            oDt.Columns.Add("Produced", GetType(Double))
snip
           q = From record In oDt
                Group By sight = record("Sight")
                Into totValueBox = Sum(record.Field(Of Double)("ValueBox")) _
                , totYield = Sum(record.Field(Of Double)("Yield")) _
                , totRoughStock = Sum(record.Field(Of Double)("RoughStock")) _
                , totPolishedStock = Sum(record.Field(Of Double)("PolishedStock")) _
                , totInProduction = Sum(record.Field(Of Double)("InProduction")) _
                , totOverhead = Sum(record.Field(Of Double)("Overhead")) _
                , totProduced = Sum(record.Field(Of Double)("Produced"))
                Order By sight
whereas what you had in mind was :
select sight, sum(ValueBox) as totalValueBox ... from (oDT) group by sight.
And good luck if you need to group by multiple fields :
   Public Sub TestLinqMultipleColumns()
        Dim o As New DataTable
        o.Columns.Add("Sight", GetType(String))
        o.Columns.Add("Account", GetType(String))
        o.Columns.Add("Amount", GetType(Double))
        o.Columns.Add("Amount1", GetType(Double))

        o.Rows.Add("S1", "A1", 1, 2)
        o.Rows.Add("S2", "A1", 2, 4)
        o.Rows.Add("S1", "A2", 3, 6)
        o.Rows.Add("S2", "A1", 4, 8)
        o.Rows.Add("S1", "A1", 5, 10)
        o.Rows.Add("S2", "A1", 6, 12)
        Dim q
        q = From record In o _
            Group By sightAndAccount = New With {Key .Sight = record("Sight"), Key .Account = record("Account")}
            Into totAmount = Sum(record.Field(Of Double)("Amount")) _
            , totAmount1 = Sum(record.Field(Of Double)("Amount1"))
            Order By sightAndAccount.Account, sightAndAccount.Account
            Select sightAndAccount.Sight, sightAndAccount.Account, totAmount, totAmount1
        For Each o1 In q
            Debug.Print(o1.ToString)
        Next
    End Sub
This used to be
select sight, account, sum(Amount) as totAmount,sum(Amount1) as totAmount1 group by Sight,Account
"for the rest of us". And frankly, how intellisense is of any use here is beyond me.

My 2 Eurocents.

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform