使用Include
后跟ThenInclude
孩子的孩子属性.子属性可能不会出现在intellisense中ThenInclude
,但只是输入它 - 它将按预期编译和操作.
var reg = _context.Registrations .Where(r => r.User.UserName == userName) .Include(r => r.Acvitities).ThenInclude(a => a.Task) .Include(r => r.Activities).ThenInclude(a => a.SomethingElse) .FirstOrDefault(); return reg;