asp.net - Want to collect only one user with current result....in linq -


i want collect distinct user message table. written query getting message user. following code

   public ilist<entities.ent_message.messagedetails> messages(decimal usernumber)     {            owncibai_examentities db = new owncibai_examentities();         var messages = db.messages.where(wh => wh.messageto == usernumber).orderbydescending(or => or.mdate).select(a => new entities.ent_message.messagedetails          {              message = a.message1.substring(0, 50) + "...",              messageid = a.messid,              name = a.user.first_name + " " + a.user.last_name,              photo = a.user.imagepath,              usernumber = (long)a.usernumber,              mydate = a.mdate,              isread = (bool)(a.isread == null ? false : a.isread == false ? false : true)          }).tolist();           return messages;     } 

but , result follows. in left pane 2 similar rows appearing. tried group did not work. result follows

user 1 message abcd user 1 message xyz ... ...

while want result user 1 --- message1 latest mesage xyz ---- message 2

thanks in advance

i'm not sure understand question, think you're trying want 1 row recent message in it. in case, don't need returning list @ all, , need take advantage of firstordefault() function make sure grab first record (or null if none exist).

public entities.ent_message.messagedetails messages(decimal usernumber) {        owncibai_examentities db = new owncibai_examentities();     var message = db.messages.where(wh => wh.messageto == usernumber).orderbydescending(or => or.mdate).select(a => new entities.ent_message.messagedetails      {          message = a.message1.substring(0, 50) + "...",          messageid = a.messid,          name = a.user.first_name + " " + a.user.last_name,          photo = a.user.imagepath,          usernumber = (long)a.usernumber,          mydate = a.mdate,          isread = (bool)(a.isread == null ? false : a.isread == false ? false : true)      }).firstordefault();       return message; } 

does need?


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -