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
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 just want to filter the RSVPs property of your Events in-place, then I guess you probably could do use something like
var events = _context.Context.Events;
foreach(var event in events)
{
// Assuming the property is named RSVPs
event.RSVPs = event.RSVPs.Where(o => o.UserName.Equals(userName));
}
return events;
I wouldn't consider it that neat though.