title: Entity Framework - complex query - and CSV export
body: <p>A relatively simple task... I need to pull data from Database and export it to CSV file. The problem is that the data is queried from several joined tables and I'm not sure what is the best way to get data using EF and serialize it.</p>
  
  <p>My SQL query is:</p>
  
  <pre><code>select o.product, o.invoicenr, o.amount as quantity, o.price, o.shipping, o.vatrate, o.datecreated, os.title as [orderstatus],ps.title as [paymentstatus], pm.title as [paymentmethod], o.datepaid, o.dateinvoice,
  c.*, a.*,
  oos.trackingcode, oos.courier, oos.datecreated as [orderstatusdate],
   p.amout, p.transactionIdentifier, p.comment, p.datecreated as [paymentcreated]
   from [order] o
      inner join Address a
          on o.shipingaddressId = a.id
      inner join Customer c
          on o.customerId = c.id
      inner join OrderOrderStatus oos
          inner join OrderStatus os
           on oos.orderstatusId = os.id
           on o.id = oos.orderID      
      inner join Payment p 
          inner join PaymentStatus ps
           on p.paymentstatusId = ps.id
          inner join PaymentMethod pm
           on p.paymentmethodId = pm.id
          on o.id = p.orderId
  order by o.datecreated, o.id
  </code></pre>
  
  <p>Combined, there are 44 columns that should be returned. </p>
  
  <p>How can I replicate this query with LINQ? What is the best way to proceed with this task in general? </p>
  
  <p>Just for understanding: There is main table "Order" which is linked one-to-many with tables Address, Customer, OrderOrderStatus and Payment. Table Payment has one-to-many relationsships with PaymentStatus and PaymentMethod. Table OrderOrderStatus has one-to-many relationship with OrderStatus.</p>
  
  <p>Thanks!</p>