M
M
MrMiller2018-08-02 10:51:03
Entity Framework
MrMiller, 2018-08-02 10:51:03

How to sort by related entity field in Entity Framework via shadow property?

result = await DbSet.Where(x => x.ParentId == parentId)
                                        .Include(x => x.CreationUser)
                                        .Include(x => x.ModifiedUser)
                                        //.OrderBy(x => x.ModifiedUser.LastName)
                                        .OrderBy(x => EF.Property<object>(x.ModifiedUser, "LastName"))
                                        .Skip(pageSize * (pageNumber - 1))
                                        .Take(pageSize)
                                        .ToArrayAsync();

Is it possible to write an OrderBy like this (x => EF.Property(x, "ModifiedUser.LastName")?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question