pretty sure its the lack of sleep and the fact i've run out of coffee but i'm really struggling to get this in my head.
So I have 2 tables, Conversations which my model is:
public class Conversation
{
[Key]
public int ConversationId { get; set; }
public ICollection<Message> Messages { get; set; } = new Collection<Message>();
}
and Messages :
public class Message
{
[Key]
public int MessageId { get; set; }
public string MessageContent { get; set; }
public string Sender { get; set; }
public string Receiver { get; set; }
public DateTime DateCreated { get; set; }
}
now in my controller method I am trying to pull in all messages if they contain the passed in users in the method
e.g
[Route("GetAllUserConversations")]
[HttpGet]
public async Task<List<Conversation>> GetAllUserConversations(string receiverEmail, string senderEmail)
{
var conversation = _dbContext.Conversations
.Include(m => m.Messages)
.SingleOrDefault(x => x.Messages.Where(x => x.Receiver == receiverEmail) && x.Messages.Where(y => y.Sender == senderEmail);
return conversation;
}
so if receiverEmail AND SenderEmail are present in the message then I want to pull in that message.
an example of the message I am trying to get is:
thanks!

var conversations = _dbContext.Conversations.Include(m => m.Messages).Where(x => x.Messages.Any(x => x.Receiver == receiverEmail && x.Sender == senderEmail)).ToListAsync();