1

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();
Colin DeClue
  • 2,194
  • 3
  • 26
  • 47
  • http://stackoverflow.com/questions/6761104/how-does-linq-expression-syntax-work-with-include-for-eager-loading try that! – kelsier Nov 20 '13 at 02:45
  • Hmm, that seems to suggest putting the `.Include` after the query, but it seems EF 4.0 doesn't have a definition for `.Include` on an `IQueryable`, only on `ObjectQuery`... – Colin DeClue Nov 20 '13 at 16:01

0 Answers0