score:0

i'd use a select to get the entities with orderby after the where but before firstordefaultasync(). like this:

var header = await _context.headers
    .include(location => location.headerlocation)
    .include(details => details.details)
    .where(p => p.headerid == headerid)
    .select(header => new header
    {
        // assign header values
        location = header.location,
        details = header.details.orderby(h => h.fieldname).orderby(h => h.lineversion)
    }).firstordefaultasync();

score:2

on top of the other suggestion i have seen, i used the link in the comments of the original post, and got a great answer there, too. i tested it, and it works like a charm. here is what i ended up with:

public async task<permitheader> getpermit(int headerid)
{
    var header = await _context.headers
            .include(location => location.location)
            .where(p => p.headerid == headerid).firstordefaultasync();
    var details = await _context.details
            .orderby(ob => ob.fieldname)
            .orderby(ob => ob.lineversion)
            .where(d => d.headerheaderid == headerid).tolistasync();
    header.details = details;
    return header;
}

thanks for a quick response!


Related Query

More Query from same tag