如何在 Entity Framework Table 关系 LINQ 方法语法中订购数据查询?

How to Order Data Query in Entity Framework Table Relationships LINQ Method syntax?

我在 table IscinstancesName 在 table 关系中排序数据时遇到问题, Iscinstances table 是 JOINLinkUsersToIscinstances table,下面是我的查询对于 table 关系。

问题是OrderBy a.LinkUsersToIscinstances.Iscinstances.Name出错了,如何修复订单查询?

var customer = await _context.Users
                            .Where(c => c.UserId  == UserId && c.LastActivityDate > date && c.IsApproved == num)
                            .Include(c => c.Profile)
                            .Include(a => a.LinkUsersToIscinstances).ThenInclude(b => b.Iscinstances)
                            .OrderBy(a => a.LinkUsersToIscinstances.Iscinstances.Name).ThenBy(c => c.LastName).ThenBy(c => c.FirstName)
                            .ToListAsync();

我正在尝试按 table 关系中的 table 行名称对数据进行排序,我希望查询按 table Iscinstances 姓名, table 用户 姓氏, table 用户 名字

这是我的经典 table 关系

UserProfile

    public virtual ICollection<LinkUsersToIscinstance> LinkUsersToIscinstances { get; set; }
    public virtual ICollection<User> Users { get; set; }

LinkUsersToIscinstance

    public virtual UserProfile Profile { get; set; }
    public virtual Iscinstance Iscinstances { get; set; }
    public virtual User Users { get; set; }

Iscinstance

    public virtual ICollection<LinkUsersToIscinstance> LinkUsersToIscinstances { get; set; }

用户

    public virtual UserProfile Profile { get; set; }
    public virtual ICollection<LinkUsersToIscinstance> LinkUsersToIscinstances { get; set; }

尝试以下查询。

var customer = await _context.Users
    .Where(c => c.UserId  == UserId && c.LastActivityDate > date && c.IsApproved == num)
    .Include(c => c.Profile)
    .Include(a => a.LinkUsersToIscinstances.OrderBy(x => x.Iscinstances.Name)).ThenInclude(b => b.Iscinstances)
    .OrderBy(c => c.LastName).ThenBy(c => c.FirstName)
    .ToListAsync();