Skip to content
Advertisement

Messaging Functionality Creating Sql query and Database View

Given the following:

enter image description here

I need to be able to get a list of all threads in which a given user has participated, sorted by most recent message first, with only the most recent message being displayed (1 message per thread)

This is the SQL query for the above:

The way this works is this. a Loginid 1 send a LoginId 2 a message:

  1. a new thread is created and a record is inserted into MessageThread

  2. a new record is added into Message table with the treadId from above

  3. TWO records are inserted into MessageThreadParticipant (Sender LoginId and Recipient LogiId)

    When a user opens his/hers list of messages MessageReadState will update ReadDate of the message.

QUESTION: I would like to create a view where I can simply filter on LoginId (I would be using LINQ). However I can’t do this with the Query above (since i would need to pass loginId somewhere within the sql statement). Is there anyway to modify the above SQL query in such way that would allow me to have a view?? what is it?

EDIT: i think i have it but i’m not sure if this is the best/most efficient solution:

Advertisement

Answer

Does this do something like what you want?

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement