1

I have a SQL query that uses cross apply to join to a table-valued function to a table as in the following in order to search what is essentially a linked list (parent and child work orders) for the first item.

select w.id newid, nod.id 
from workorder
inner join entity woe on w.id = woe.id
cross apply NODWorkorder(w.id) nod
where woe.entity = 'aguid'

NODWorkorder returns a WORKORDER row that is the original parent work order. All ids are defined as varchar.

How would I convert this to LINQ? I am using EF Core 8.

I was able to import the TVF into the model as a WORKORDER type (using database first and EF Core Power Tools extension), but I can't figure out how to give the TVF the work order id from the work order table.

nodworkorders = (from wo in wdc.WORKORDERs
                 join woe in wdc.entity on wo.ID equals woe.ID
                 join NODs in wdc.NODWorkorder(wo.id) on wo.ID equals NODs.ID
                 select wo).ToList();

The code shown here doesn't recognize wo.id as a parameter to NODWorkorder.

1 Answer 1

1

For cross apply you have to use just additional from, not join.

var query =
    from wo in wdc.WORKORDERs
    join woe in wdc.entity on wo.ID equals woe.ID
    from NODs in wdc.NODWorkorder(wo.id)
    where woe.entity == "aguid"
    select wo;

var nodworkorders = query.ToList();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.