Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i select last conversation messages to users From below table of Id 1 that may be in FromId or ToId


CSS
MessageId  FromId  ToId Message      Time                  Status

19            1     5   hiii    2013-07-05 16:39:49.727     New
21            5     1   message   2013-07-10 11:19:53.733    New
25            5     1   dfdfdf  2013-07-07 00:00:00.000     New
29            1     8    dsfas    2013-07-07 00:00:00.000    New
30            8     1   asdfjas   2013-07-07 02:00:00.000   New


Required Output:-

XML
MessageId  FromId  ToId Message      Time                  Status

21            5     1   message   2013-07-10 11:19:53.733    New
30            8     1   asdfjas   2013-07-07 02:00:00.000   New
Posted

C#
var ResultData = from Data in db.TableName
                 where Data.FromId==1
                 select Data;


where db=DataclassDataContext()

All the data regarding your ID is in ResultData variable....:)
 
Share this answer
 
v2
Comments
Jithin Geroge 15-Jul-13 9:01am    
Above table is message table it contain users from messages and to messages . It seperated by FromId and ToId . I need last conversation of particular user say user with id= 1 to different users that Id=1 sended or received messages. How can i select??
Nirav Prabtani 15-Jul-13 9:04am    
what r u saying i can not understand???
Jithin Geroge 15-Jul-13 9:12am    
Very recent conversations by date of User with id=1
Nirav Prabtani 15-Jul-13 9:15am    
then you have to select max date from table... :)
Jithin Geroge 15-Jul-13 9:32am    
Sorry .. please give a brief example..
A simple linq query that selects the rows where the ToId equals 1 (as in your "required output")

C#
DateTime start = new DateTime("1/1/2013");
var result = (from a in new YourDataContext().YourTableName
              where ((a.ToId == 1 || a.FromId == 1) && a.Time >= start)
              select a);



If it's not what you intended, explain a little more, and we will provide ;)

Good luck,
Edo
 
Share this answer
 
v2
Comments
Jithin Geroge 15-Jul-13 9:01am    
Above table is message table it contain users from messages and to messages . It seperated by FromId and ToId . I need last conversation of particular user say user with id= 1 to different users that Id=1 sended or received messages. How can i select??
Joezer BH 15-Jul-13 9:12am    
In your example above the results are from two different users (5 and 8):

MessageId FromId ToId Message Time Status

21 5 1 message 2013-07-10 11:19:53.733 New
30 8 1 asdfjas 2013-07-07 02:00:00.000 New
Jithin Geroge 15-Jul-13 9:14am    
Very recent conversations by date of User with id=1 , Id may be in FromId or in toId according to received message or sent message
Joezer BH 15-Jul-13 9:20am    
OK updated the solution above to accomodate,
Good luck,
Edo ;)
Jithin Geroge 15-Jul-13 9:35am    
I tried with above query.. I getting message from date 1/1/2013 .
But I need not that.. I need Very recent conversations by date of User with id=1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900