.NET Framework - linq max/min with strings

Asked By SIS01 on 04-Jul-11 07:20 PM
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




Armin Zingler replied to SIS01 on 04-Jul-11 08:33 PM
Am 05.07.2011 01:20, schrieb SIS01:


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)




--
Armin
SIS01 replied to Armin Zingler on 05-Jul-11 01:10 PM
Am 05.07.2011 01:20, schrieb SIS01:


This should do it:
Hi!

Min(item.title)   only works with numbers


--
Armin
Armin Zingler replied to SIS01 on 05-Jul-11 02:53 PM
Am 05.07.2011 19:10, schrieb SIS01:


I did not add items to the array but syntactically it works. Why should not
it work with strings? Strings are comparable, too.

--
Armin