linq max/min with strings

  • Thread starter Thread starter SIS01
  • Start date Start date
S

SIS01

im new in LINQ,

i've lookin for max/min functions for strings or dates to use in grouping
queries:

by example, i like to get the author and the min title of their books.

AUTHOR TITLE
---------------------
PLATON OMEGA

PLATON LAMDA

PLATON DELTA

DANTE BETA

DANTE ALPHA

DANTE ALFER

if i write in SQL:

SELECT author, MIN(title) AS mintitle FROM books GROUP BY author


AUTHOR mintitle
---------------------
PLATON DELTA

DANTE ALFER

and it works fine!
its simple and clear.



How can i get the same in LINQ?

Thanks in advance
 
Am 05.07.2011 01:20, schrieb SIS01:
im new in LINQ,

i've lookin for max/min functions for strings or dates to use in grouping
queries:

by example, i like to get the author and the min title of their books.

AUTHOR TITLE
---------------------
PLATON OMEGA

PLATON LAMDA

PLATON DELTA

DANTE BETA

DANTE ALPHA

DANTE ALFER

if i write in SQL:

SELECT author, MIN(title) AS mintitle FROM books GROUP BY author


AUTHOR mintitle
---------------------
PLATON DELTA

DANTE ALFER

and it works fine!
its simple and clear.



How can i get the same in LINQ?

Thanks in advance


This should do it:

Structure bla
Public author, title As String
End Structure

Dim items As bla()

Dim q = From item In items _
Group By item.author Into MinTitle = Min(item.title)
 
Am 05.07.2011 01:20, schrieb SIS01:
im new in LINQ,

i've lookin for max/min functions for strings or dates to use in grouping
queries:

by example, i like to get the author and the min title of their books.

AUTHOR TITLE
---------------------
PLATON OMEGA

PLATON LAMDA

PLATON DELTA

DANTE BETA

DANTE ALPHA

DANTE ALFER

if i write in SQL:

SELECT author, MIN(title) AS mintitle FROM books GROUP BY author


AUTHOR mintitle
---------------------
PLATON DELTA

DANTE ALFER

and it works fine!
its simple and clear.



How can i get the same in LINQ?

Thanks in advance


This should do it:
Hi!

Min(item.title) only works with numbers
 
Am 05.07.2011 19:10, schrieb SIS01:
This should do it:
Hi!

Min(item.title) only works with numbers

I didn't add items to the array but syntactically it works. Why shouldn't
it work with strings? Strings are comparable, too.
 
Back
Top