linq max/min with strings

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
 
A

Armin Zingler

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)
 
S

SIS01

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
 
A

Armin Zingler

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top