I've got a Payment, which has a UserAccountId on it, which references a table called User_Account. I want to load the related User_Account with my query. It's always coming back null, even if I explicitly call .Include("User_Account"). Additionally, other related fields are not loading for Payment, even if I explicitly include them.
If I look at other Entities, their related entities are loaded without explicitly asking for them. If I do ctx.User_Account.ToList(), the (there's only one) User_Account has a list of Payments (of just one -- the one I'm looking for).
The UserAccountId is a foreign key in the DB, and it is populated on the entity I'm looking at. Here's my code:
var payments = (from p in ctx.Payments.Include("User_Account")
join pi in ctx.PaymentInvoices on p.Id equals pi.PaymentId
where (p.UserId == userId || userId == -99) &&
(string.IsNullOrEmpty(searchParams.DocumentNumber) || p.TransactionID == searchParams.DocumentNumber) &&
(string.IsNullOrEmpty(searchParams.PONumber) || pi.PONumber == searchParams.PONumber) &&
(string.IsNullOrEmpty(searchParams.SelectedStatus) || p.Status == searchParams.SelectedStatus) &&
(searchParams.SelectedBillTos.Contains(pi.CustomerId))
select p).Distinct();
return payments.ToList();