Entity Framework loading child collection with sort order

前端 未结 3 1751
滥情空心
滥情空心 2020-11-28 08:49

I have two tables a parent and a child table. The child table has a column sortorder (a numeric value). Because of the missing support of the EF to persist a IList inclusive

3条回答
  •  生来不讨喜
    2020-11-28 09:07

    In addition to needing to order, I needed to limit the results of the children. I did it like this:

    var transactions = await _context.Transaction
                .Include(x => x.User)
                .OrderByDescending(x => x.CreatedAt)
                .Where(x => x.User.Id == _tenantInfo.UserId)
                .Take(10)
                .ToListAsync();
    
    var viewmodel = _mapper.Map(transactions.First().User);
    

提交回复
热议问题