我在表关系中按表Iscinstances行Name对数据进行排序时遇到问题,Iscinstances表是LinkUsersToInistances表中的JOIN,下面是我对表关系的查询。
问题是OrderBya.LinkUsersToIcisinstances.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();
我正在尝试按表关系中的表行名称对数据进行排序,我想让查询按表Iscinstancesname、表用户LastName户FirstName对它们进行排序
这是我的classis表关系
UserProfile
public virtual ICollection<LinkUsersToIscinstance> LinkUsersToIscinstances { get; set; }
public virtual ICollection<User> Users { get; set; }
链接用户当前
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();