Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Linq Syntax
Message
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Titre:
Versions des environnements
Environment:
VB 8.0
OS:
Vista
Network:
Windows XP
Database:
Jet/Access Engine
Application:
Desktop
Divers
Thread ID:
01524641
Message ID:
01524658
Vues:
52
>Can this be done in one statement, i.o.w how do I define an Order By clause with a select Group Select New construction?
>
>
>        Dim orders As IEnumerable(Of DataRow) = osql.dt.AsEnumerable
>        Dim Test2 = From r In orders _
>            Group r By nummer = r.Field(Of String)("KL_Nummer"), name = r.Field(Of String)("KL_Naam"), artBtw = r.Field(Of Double)("ArtBtw") _
>            Into g = Group Select New With {.Nummer = nummer, .Name = name, .artbtw = artBtw, .total = g.Sum(Function(r) _
>                r.Field(Of Decimal)("Bestd_Waarde") * (1.0 - CDbl(If(r("art_korting") = False, 0.0, If(r("kkkorting") Is DBNull.Value, CDbl(r("KLkorting")), CDbl(r("KKKorting")))))))}
>        Dim test = From r In Test2 Order By r.Name
>
Why bother. You are only building a query which will not be executed until the IEnumerable is evaluated. For example try this:
            IEnumerable<string> list = new List<string>() { "One", "Two", "Three" };
            var test2 = (from s in list select s);

            foreach (string s in test2)
                Console.WriteLine(s);

            Console.WriteLine("-----------------");
            ((List<string>)list).Add("Four");
            var test = from s in test2 orderby s ascending select s;

            foreach (string s in test)
                Console.WriteLine(s);

            Console.ReadLine();
UPDATE. Guess I assumed you were making the switch to C# :-}
Here's a supposed VB.NET equivalent (except I see it didn't translate the linq :-{ ):
Dim list As IEnumerable(Of String) = New List(Of String)() With { _
	"One", _
	"Two", _
	"Three" _
}
Dim test2 = ()

For Each s As String In test2
	Console.WriteLine(s)
Next

Console.WriteLine("-----------------")
DirectCast(list, List(Of String)).Add("Four")
Dim test = _
	Order By s Ascending

For Each s As String In test
	Console.WriteLine(s)
Next

Console.ReadLine()
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform