I'm working in asp.net mvc and I have a unique situation.
I have two tables.
A user can create a new message and then add more users to the message. Currently, the user who creates the message is not saved as a MessageUser, but instead just at the message level.
However, in other situations this same user might be added as a MessageUser to another message.
I'm trying to display all messages that pulls from two lists:
- a list of messages where the user created the message.
- a list of messages that a user is an added user in the MessageUser table that lies below the Message table.
My attempts so far have fallen short.
var userId = User.Identity.GetUserId(); //Pulls all messages where the user created them. List<Message> MessageList_1 = db.Message.Where(u => u.UserId == userId).ToList(); //This doesn't work at all, but it's what I'm hoping to do in English. //I want a list of just the messages where a messageuser is associated to the messageid. List<Message> MessageList2 = db.MessageUser.Where(u => u.UserId == userId).ToList(); //Another failed attempt List<Message> MessageList3 = db.Message.Where(u => u.MessageId = MessageUserList.) //Original that just pulls messages the user created. My hope is to combine the two lists and display them on the same view. var message = db.Message.Include(o => o.User).Where(u => u.UserId == userId); return View(await Message.ToListAsync());
Hope this is enough.