I need to return a list of all the events and any rsvps a user may have for an event. However, regardless of the username I pass, It returns every single rsvp. My linq Query ->
return (from events in this._context.Context.Events
join rsvps in (this._context.Context.RSVPs
.Where(o=> o.UserName == userName))
on events equals rsvps.Event into re
from rsvps in re.DefaultIfEmpty()
select events);
Relationship is
Events.EventID = RSVPs.EventID
from e in _context.Context.Events
join r in _context.Context.RSVPs.Where(o => o.UserName == userName)
on e.EventID equals r.EventID into g
select new {
Event = e,
Rsvps = g
};
Do it this way:
return (from events in this._context.Context.Events
join rsvps in this._context.Context.RSVPs
on events.EventIDequals equals rsvps.EventID into re
from c in re.DefaultIfEmpty()
where c.UserName == userName
select new {events,rsvps});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With