Question: I am trying to replicate this loop as an IQueryable:

```
        foreach (var book in BookList)
        {
            foreach (var a in book.Authors)
            {
                if (a.AuthorId.ToString() == Id)
                {
                    AuthorView = new AuthorViewModel(a, item.BookId);
                }
            }
        }

```

I have tried:

```
var Test = _context.Book.Include(x => x.Authors)
  SelectMany(y => y.Authors).ToList().FirstOrDefault(x => x.AuthorId.ToString() == Id)
.Select(x => new AuthorViewModel(x, ??.BookId);

```

But I get stuck trying to create the object AuthorViewModel as it requires the BookId that I can no longer access. Is there a way of passing the book Id down?

Sorry, just release the example doesn't make sense.

Books is a table in a database.
Authors is a table in the database which contains many authors.

```
Book:
BookId
Authors

Authors:
AuthorId
Name
DOB

```

AuthorList should have been BookList (List). I have corrected this.

I am trying to locate an author based on an author id - and return it in an object (Author, BookId (from the book table))

Answer: 
Try to do like this: 

```
public function show($id)
    {
        $user = Auth::user();
        $order = Order::with(['orderLines', 'orderLines.product'])
                      ->where('user_id', '=', $user->id)
                      ->findOrFail($id);
        return view('layouts/order/index', compact('order'));
    }

```

```
class OrderLine

public function order()
    {
        return $this->belongsTo(\App\Order::class, 'order_id');
    }

    public function product()
    {
        return $this->belongsTo(\App\Product::class, 'product_id');
    }

```

```
class Order

 public function orderLines()
    {
        return $this->hasMany(\App\OrderLine::class);
    }

```

Change name of `orderLine` to `orderLines` because order has many orderLines.

And in your blade: 

```
@foreach($order->orderLines as $orderLine)
<tr>
    <td>{{$orderLine['product']->title}}</td> 
<tr>
@endforeach

```
give it a try -

```
    @foreach($order as $ordr)
    <tr>
    <td>{{$ordr->product_id->name}}</td>
    <tr>
    @endforeach

```