I'm working in asp.net mvc and I have a unique situation.
I have two tables.
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());
If there is a foreign key relationship set up properly then you can do something like this )
List<Message> MessageList_2 = db.MessageUser.Where(u => u.UserId == userId).Select(m=> m.Message).ToList(); MessageList_1.AddRange(MessageList_2);
MessageList_1 should contain your answers. You may need to look into selecting distinct messages by id as well. If you're foreign key properties aren't correct, then this won't work and you'll and up with a lot of other problems as well.