Select distinct values

Feb 2, 2011 at 6:08 PM
Edited Feb 4, 2011 at 1:11 PM

Hi, here is what my database looks like

MessageId, ConversationId, Text

1,1,"test1"

2,1,"test2"

3,2,"test3"

4,3,"test4"

5,3, "test5"

What I want is the last message of each discussion :

2,1,"test2"

3,2,"test3"

5,3,"test5"

In sql, it sould be something like that : 

select conversationId, max(messageId), text FROM test_ds GROUP BY conversationId

Is it possible to do it with Linq in Sterling?

 

thx

Feb 4, 2011 at 1:34 PM

Ok :)

I found how to deal with it :D

 

var query = from s in ds.Database.Query<Message, int>() group s by s.LazyValue.Value.ConversationId into g select g.Last();

 

 

Coordinator
Feb 14, 2011 at 2:07 PM

I'm sorry it took me so long to respond. I was researching some tutorials to point you to as LINQ to Object is fully supported but I see you found the solution - thanks for posting it!